Question

I'm getting an error when trying to build a project regarding unresolved external symbols, however I can't find out where my issue lies, anyone got any ideas? thanks

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

Error:

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 ==========

Nothing I've tried seems to work for me.

Était-ce utile?

La solution

Put this into your cpp:

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

This make the "space" for these member static variables.

Autres conseils

I dont see the definitions of

static TVector Position;
static TVector Verlocity;

This are the declarations only. You will need to define it, using some contructor (posible the default one) in one .ccp file. The static members are not part of each object and need to be created in a place other than an object constructor.

In your case:

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(){}

Most likely (as there is no errors posted) you miss definition of

static TVector Position;
static TVector Verlocity;

To fix this add

Tball::Position(70,0,70);
Tball::Verlocity(1,0,1);

to your .cpp, and remove its initialization from constructor.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top