c++ - 没有命名类型错误 C++

标签 c++ compiler-errors g++

我已将代码分隔在两个文件中,如下所示。这是头文件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。我不明白为什么会这样。任何帮助表示赞赏。

最佳答案

来源的第一行。

#ifdef GRAPH_H

应该是

#ifndef GRAPH_H

关于c++ - 没有命名类型错误 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16780009/

相关文章:

c++ - gcc 静态分析器 (Weffc++) : exclude directories

c++ - 绘制的自定义项目有时会在 QGraphicsScene 中被砍掉

c++ - 按不同字段对结构队列进行排序

c++ - UE4项目链接错误,描述为空

c++ - 另一个 "ISO C++ forbids declaration"错误

c++ - 未使用 MinGW 的 g++ 编译器在此范围内声明 GetCurrentHwProfile

c++ - 用C++实现AVL add?

c++ - 交叉编译: special cross compiler or just gcc with option -march?

g++ - g++编译错误: missing ';'

macos - MacOSX 上的 g++ 不适用于 -arch ppc64