2013-05-27 48 views
0

我已經將代碼隔離在兩個文件中,如下所示。這裏是頭文件graph.h不會命名類型錯誤C++

//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。我不明白爲什麼會發生這種情況。任何幫助讚賞。

+0

再看看你的包括graph.h警衛。 –

+0

是的。瞭解。這件事讓我感到沮喪。 –

+0

然後使用'#pragma once'代替守衛。 – kfsone

回答

5

來源的第一行。

#ifdef GRAPH_H 

應該

#ifndef GRAPH_H