C++ C++;名称空间;首先在此处定义”的含义;缺陷
所以我在编译时遇到了一个奇怪的错误。我在这篇文章的底部提供了一个bug的图片,你也可以在这里查看bug列表: 代码:C++ C++;名称空间;首先在此处定义”的含义;缺陷,c++,sfml,C++,Sfml,所以我在编译时遇到了一个奇怪的错误。我在这篇文章的底部提供了一个bug的图片,你也可以在这里查看bug列表: 代码: \ifndef水电站首席财务官 #定义CFO_水电站 #包括 #包括 类资源 { 公众: //方法 std::stringgetword(std::stringl,intx); std::stringgetwords(std::stringl,intx,inty); int getWordCount(std::string l); }; 类外壳; 命名空间cfo { //变数 静
\ifndef水电站首席财务官
#定义CFO_水电站
#包括
#包括
类资源
{
公众:
//方法
std::stringgetword(std::stringl,intx);
std::stringgetwords(std::stringl,intx,inty);
int getWordCount(std::string l);
};
类外壳;
命名空间cfo
{
//变数
静态标准::字符串版本=“-Alpha[0.1]”;
静态int屏幕截图=0;
//班级
Res;//工具等。
//shell配置;
//壳牌gfx;
//方法
空屏幕快照(sf::渲染窗口和窗口);
};
void cfo::screenshoter(sf::RenderWindow&window)//这是一个.cpp文件,但我把它移到了这里。
{
sf::Image screen=window.capture();
screen.saveToFile(屏幕截图+“.jpg”);
截图++;
}
#恩迪夫
错误图片:这不是错误,只是部分错误。错误在于你违反了“一个定义”规则。我想我已经找到了其中的一部分。我有多个文件,包括代码中的标题。我怎么能让多个文件包含某些内容,但只定义一次名称空间?名称空间不是问题,但你应该在标题中声明内容,并在实现文件中定义它们。啊,所以,当我定义“res”对象时。我应该在namespaces.cpp文件中这样做?@user是的。还包括函数定义。
#ifndef CFO_HPP
#define CFO_HPP
#include <string>
#include <SFML/Graphics.hpp>
class Res
{
public:
// Methods
std::string getWord(std::string l, int x);
std::string getWords(std::string l, int x, int y);
int getWordCount(std::string l);
};
class shell;
namespace cfo
{
// Variables
static std::string version = "- Alpha [0.1]";
static int screenshot = 0;
// Classes
Res res; // Tools etc.
//shell config;
//shell gfx;
// Methods
void screenshoter(sf::RenderWindow &window);
};
void cfo::screenshoter(sf::RenderWindow &window) // This was in a .cpp file, but I moved it here.
{
sf::Image screen = window.capture();
screen.saveToFile(screenshot + ".jpg");
screenshot++;
}
#endif