簡體   English   中英

未解析的外部符號,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:\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 */);

這使得這些成員靜態變量成為“空間”。

我沒看到的定義

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,並從構造函數中刪除它的初始化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM