未解析的外部符号,c++
unresolved external symbol, C++
当试图建立一个关于未解决的外部符号的项目时,我得到了一个错误,但是我找不到我的问题在哪里,有人有任何想法吗?由于
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:worksecond yearc++ breakout completebreakout completetball.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:WorkSecond yearC++ Breakout CompleteDebugBreakout 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 */);
我没有看到
的定义static TVector Position;
static TVector Verlocity;
这只是声明。您需要在一个.ccp文件中使用一些构造函数(可能是默认的)来定义它。静态成员不是每个对象的一部分,需要在对象构造函数以外的地方创建。
在你的例子中:
Tball.cpp
#include "Tball.h"
#include <Windows.h> // Why?
//using namespace std; Why??
TVector Tball::Position(70,0,70);
TVector Tball::Verlocity(1,0,1);
Tball::Tball(){}
很可能(因为没有发布错误)您错过了
的定义static TVector Position;
static TVector Verlocity;
要解决这个问题,添加
Tball::Position(70,0,70);
Tball::Verlocity(1,0,1);
到你的.cpp,并从构造函数中删除它的初始化。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- VC++本机单元测试,找不到调试符号
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- 检查TCHAR数组输入是否为带符号整数C++
- 用符号版本替换对函数的所有调用
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何打印boost多精度128位无符号整数
- C++模板函数,用于比较任何无符号整数和有符号整数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号