c ++“class”没有命名类型

时间:2013-04-09 21:13:36

标签: c++

我有点问题但不确定它是什么。

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()
{

}

很抱歉放入整个代码,但我不想承担任何风险。 错误: g ++ -Wall -g -c -o Continent.o Continent.cpp -MMD -MF ./Continent.o.d Continent.cpp:13:1:错误:'Continent'没有命名类型

从那我得到它是标题定义和.cpp之间的问题,但是什么是我看不到的问题。

thx任何帮助:)

1 个答案:

答案 0 :(得分:4)

您在标题中的名称空间Continent中声明了Sep,但在.cpp中,您在全局范围内使用Continent,而未在其中定义。{/ p>

您应该在.cpp中的using namespace Sep;之后添加#include,在namespace Sep { ... }中包含所有定义,或者在每次使用Sep::之前添加Continent {1}}。