2013-04-09 112 views
0

我有一点问题,但不知道它是什么。C++“class”does not name a type

header.h:

#ifndef CONTINENT_H_INCLUDED 
#define CONTINENT_H_INCLUDED 

#include <string> 
#include <vector> 

class Territory; 
class Player; 

namespace Sep 
{ 

    //---------------------------------------------------------------------------- 
    // Continent class 
    // class consist of many territories 
    // 
    class Continent 
    { 
    private: 

    public: 

     //-------------------------------------------------------------------------- 
     // Constructor 
     // 
     Continent(); 


     //-------------------------------------------------------------------------- 
     // Copy Constructor 
     // Makes a copy of another Continent Object. 
     // @param original Original to copy. 
     // 
     Continent(const Continent& original); 


     //-------------------------------------------------------------------------- 
     // Assignment Operator 
     // Used to assign one Continent to another 
     // @param original Original with values to copy. 
     // 
     Continent& operator= (Continent const& original); 


     //-------------------------------------------------------------------------- 
     // Destructor 
     // 
INCLUDED 

virtual ~Continent(); 

    //-------------------------------------------------------------------------- 
    // Constructor to forward attributes 
    // 
    Continent(std::string name, std::vector<Territory*> territories); 

    }; 
} 

#endif // CONTINENT_H_INCLUDED 

的.cpp:

#include "Continent.h" 

//------------------------------------------------------------------------------ 
Continent::Continent() 
{ 

} 

//------------------------------------------------------------------------------ 
Continent::Continent(std::string name, std::vector<Territory*> territories) : 
       name_(name), territories_(territories) 
{ 

} 
//------------------------------------------------------------------------------ 
Continent::~Continent() 
{ 

} 

对不起,我把整个代码,但我不想冒任何风险。 ERROR: 克++ -Wall -g -c -o Continent.o Continent.cpp -MMD -MF ./Continent.od Continent.cpp:13:1:错误: '洲' 没有指定类型

从那我得到它是头定义和.cpp之间的问题,但最新的问题,我不能看到它。

THX任何帮助:)

+6

你把它放到'namespace'中是有原因的,不是吗? 'Sep :: Continent :: Continent()' – 2013-04-09 21:15:18

+2

在析构函数上面做那个流浪'INCLUDED'是什么? :) – fredoverflow 2013-04-09 21:20:54

回答

4

你在你的头的命名空间Sep宣布Continent,但在你的.cpp,你在全球范围内,它是没有定义使用Continent

您应该在您的.cpp的#include后添加using namespace Sep;,包裹在一个namespace Sep { ... }所有定义,或把Sep::在每次使用的Continent的前面。

+3

不,不要'使用命名空间Sep;'如果你想避免所有'Sep ::'的;而是将所有定义包装在'namespace Sep'上下文中。 – 2013-04-09 21:30:35

+0

omg * facepalm *自己对不起:)已经晚了 – vicR 2013-04-09 22:02:10

相关问题