gpt4 book ai didi

c++ "class"没有命名类型

转载 作者:行者123 更新时间:2023-11-27 23:16:33 25 4
gpt4 key购买 nike

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

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

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

感谢任何帮助:)

最佳答案

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com