【问题标题】:does not name a type error c++没有命名类型错误 C++
【发布时间】:2013-05-27 20:17:20
【问题描述】:

我已将代码分隔在两个文件中,如下所示。这里是头文件graph.h

//graph.h
#ifdef GRAPH_H
#define GRAPH_H

#include <vector>
#include <fstream>

#include "kernel_def.h"

using namespace std;

typedef vector<bool> Array;
typedef vector<Array> TwoDArray;

class baseGraph {
    private:
        int nodes;  /*Number of nodes.*/
        vector<feature_vector *> vec;   /*vector of feature nector.*/
    public:
        baseGraph(int nodes);
        /*set-get functions*/
        int getNodes();
        void setNodes(int nodes);
        const feature_vector *getVec(int pos);
        int setVec(int pos, feature_vector *fVec);

        /*Input edges from file and set up in corresponding representation.*/
        virtual void setGraph(ifstream &ipf) = 0;

        /*Utility functions*/
        virtual void printGraph() = 0;
        virtual feature_vector *subgraph_d(int node, int depth) = 0;    /*subgraph upto depth d.*/
};

这里是graph.cpp

//graph.cpp
#include <iostream>

#include "graph.h"

using namespace std;

baseGraph::baseGraph(int nodes) {
    setNodes(nodes);
    /*feature vetors will be assigned later.*/
    vec.resize(nodes);
    for(int i=0;i<nodes; ++i)
        vec.at(i) = NULL;
}

编译时出现src/graph.cpp:7:1: error: ‘baseGraph’ does not name a type 错误。我不明白为什么会这样。任何帮助表示赞赏。

【问题讨论】:

  • 再看看你在graph.h中的包含守卫。
  • 是的。知道了。这件事让我很沮丧。
  • 那么使用#pragma once 代替守卫。

标签: c++ compiler-errors g++


【解决方案1】:

源代码的第一行。

#ifdef GRAPH_H

应该是

#ifndef GRAPH_H

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多