尝试构建有关未解决的外部符号的项目时出现错误,但是我找不到问题所在,有人有任何想法吗?谢谢
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/