成员函数已在.obj(visual studio)中定义
Member function already defined in .obj (visual studio)
我在代码块中从未遇到过这个问题,但在visual studio中,类给了我错误LNK2005。。。已经在xx.obj中定义了。我读过很多答案,其中大多数都说使用"extern",我认为这在成员函数上不可用
Error: 1>Source.obj : error LNK2005: "public: __thiscall Game::Game(void)" (??0Game@@QAE@XZ) already defined in game.obj
Error: fatal error LNK1169: one or more multiply defined symbols found
如何在不使用暴力/允许多个定义的情况下解决此问题?
//game.h
#ifndef GAME_H
#define GAME_H
#include <SFML/Graphics.hpp>
class Game
{
public:
Game();
private:
sf::RenderWindow mWindow;
sf::CircleShape mPlayer;
};
#endif
//game.cpp
#include "..Headersgame.h"
Game::Game()
: mWindow(sf::VideoMode(640, 480), "Beginning")
, mPlayer()
{
mPlayer.setRadius(40.f);
mPlayer.setPosition(100.f, 100.f);
mPlayer.setFillColor(sf::Color::Cyan);
}
//source.cpp
#include "game.cpp"
int main()
{
Game game;
}
在源中替换.cpp
#include "game.cpp"
通过
#include "game.h"
您永远不应该包含*.cpp.
相关文章:
- Visual Studio中的函数声明和函数定义问题
- Android Studio:如何在build.gradle中定义自定义宏(针对不同的构建变体),并让原生C / C++
- Visual Studio C++ PlaySound 标识符未定义
- C2011 'CMemDC':Visual Studio 2019中的'class'类型重新定义
- 更改 git 分支名称后,在项目的 Visual Studio 代码中丢失智能感知(建议,转到定义C++
- 定义 uint= "unsigned int" 没有像我在 Visual Studio 中使用 nvcc 时预期的那样应用
- 如何在 Visual Studio C++ 11 中运行时定义二维数组?
- Visual Studio 2019 概念标识符未定义
- Visual Studio:snprintf 冲突的宏定义
- 标识符"DDRB"未定义 - VS code / Visual Studio
- 在Visual Studio代码中包含自定义c++库的问题
- 在Visual Studio代码中定义DEBUG和RELEASE符号
- 在 Visual Studio 2010(及更高版本)中定义包含或链接路径变量的位置
- 标识符"__readgsqword"未定义 - Visual Studio 2017
- Visual Studio 2017 C++,如何定义一个"环境变量"'Additional Library Directory'?
- 如何在 Visual Studio 中使用多个文件时阻止重新定义类
- Visual Studio Code C++ 删除 c_cpp_properties.json 中的"定义"
- std::cout 如果从自定义分配器 (Visual Studio 2019) 调用,则不会输出
- 标识符uint8_t未定义 - Visual Studio 2017
- 停止visual studio定义中的环境路径扩展