c++ - 未解析的外部符号,C++

标签 c++ unresolved-external

我在尝试构建有关未解析的外部符号的项目时遇到错误,但是我无法找出我的问题所在,有人有任何想法吗?谢谢

Tball.cpp

#include "Tball.h"
#include <Windows.h>
using namespace std;



Tball::Tball(){

 Position = TVector(70,0,70);
 Verlocity = TVector(1,0,1);

}

Tball.h

#ifndef Tball_h
#define Tball_h

#include <iostream>
#include "mathex.h"
#include "tvector.h"


class Tball
{

public:

static TVector Position;
static TVector Verlocity;


Tball();
static void DrawBall(float x, float y, float z);
static TVector MoveBall();
static void init();
static int loadbitmap(char *filename);
static void SurfaceNormalVector();
static double Tball::collision();
static void Tball::pointz();



};


#endif

错误:

1>------ Build started: Project: Breakout Complete, Configuration: Debug Win32 ------
1>  Tball.cpp
1>  Generating Code...
1>g:\work\second year\c++ breakout complete\breakout complete\tball.cpp(59): warning     C4715: 'Tball::MoveBall' : not all control paths return a value
1>  Skipping... (no relevant changes detected)
1>  Tvector.cpp
1>  TdisplayImp.cpp
1>  TBricks.cpp
1>Tball.obj : error LNK2001: unresolved external symbol "public: static class     TVector     Tball::Verlocity" (?Verlocity@Tball@@2VTVector@@A)
1>Tball.obj : error LNK2001: unresolved external symbol "public: static class     TVector     Tball::Position" (?Position@Tball@@2VTVector@@A)
1>G:\Work\Second year\C++ Breakout Complete\Debug\Breakout Complete.exe : fatal error     LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我尝试过的任何东西似乎都不适合我。

最佳答案

将其放入您的 cpp 中:

TVector Tball::Position(/* contructor params */);
TVector Tball::Verlocity(/* contructor params */);

这为这些成员静态变量创建了“空间”。

关于c++ - 未解析的外部符号,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15949055/

相关文章:

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

无法在 VS 2019 上以 Release模式为 SDL 库构建解决方案

c++ - cmake:读取并编译动态生成的 cpp 文件列表

c++ - 如何解决此 VC++ 6.0 链接器错误?

c++ - LNK2001 : unresolved external symbol "void __cdecl func1(struct Stru1 *)"

c++ - 判断Unicode字符串是否在C++中具有唯一字符的最有效方法是什么?

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

c++ - 为什么 srand(time(NULL)) 即使我反复重置它也能顺利工作?

c++ - 我可以从不是由 nvcc 编译的 C++ 代码调用 CUDA 运行时函数吗?

c++ - 如何使用 std::lower_bound 比较没有第二个对象的对象变量