0

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

标头.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.od Continent.cpp:13:1:错误:“大陆”没有命名类型

从那我知道这是标题定义和.cpp之间的问题,但是我看不到那里的问题。

谢谢任何帮助:)

4

1 回答 1

4

您在标头Continent的命名空间Sep中声明,但在 .cpp 中,您Continent在未定义的全局范围内使用。

您应该在 .cpp 中的using namespace Sep;之后添加,将所有定义包装在 a 中,或者放在每次使用.#includenamespace Sep { ... }Sep::Continent

于 2013-04-09T21:18:07.657 回答