Class problem

This is a discussion on Class problem within the C++ Programming forums, part of the General Programming Boards category; Hello i have come here to this forum to ask for help as i have run into a problem while ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    Class problem

    Hello i have come here to this forum to ask for help as i have run into a problem while writing a program.

    I have a class who is supposed to update the simulation with a declaration of two instances of a data type class called vektor. When the linker arrives to the update class's constructor, GCC give the following error messages:

    undefined reference to `vektor::vektor()'
    undefined reference to `vektor::vektor()'
    undefined reference to `vektor::vektor()'
    undefined reference to `vektor::vektor()'
    undefined reference to `vektor::vektor()'

    What is wrong?

    If i comment out "vektor ForceNy;" and "vektor ForceNy;" in UpdateSim and all references to them in the update function it compiles.

    Here are the relevant parts of UpdateSim and vektor.

    Code:
    class UpdateSim
    {
    public:
    	UpdateSim();
    	~UpdateSim();
    	int update();
    
    	__int64 SimTime; //How long time has the simulation simulated
    
    private:
    	//Temp variabler till updaterings functionen
    	vektor ForceNy; //The newly calculated force, is going to be added to Fres of the curent object
    	vektor ForceNy; //Temporary variable distance used in calculations
    
    	long double G; //The gravitational constant.
    	unsigned int Tids_steg; //Hur lång tid går det för varje uppdatering i sekunder
    };
    
    UpdateSim::UpdateSim()
    {
    	//Initialize Simulation variabels
    	G=1064407456253852709838460.8053915;
    	Tids_steg=3600;
    	SimTime=0;
    }
    Code:
    class vektor
    {
    public:
        //Defult Constructor
        vektor();
    	//Constructor from 4 cordinats
    	vektor(long double sX, long double sY, long double eX, long double eY);
    
    	//Constructor from 2 cordinats a magnitude and a heading
    	vektor(long double sX, long double sY, long double Mag, float Hed);
    
    	//Destructorn
    	~vektor();
    
    	//Negering
    	vektor& operator-();
    
    	//Tilldelning
    	vektor operator=(vektor const& envek);
    
    	//Jämförelser
    	bool operator!=(vektor const& envek);
    	bool operator==(vektor const& envek);
    	bool operator<(vektor const& envek);
    	bool operator>(vektor const& envek);
    	bool operator<=(vektor const& envek);
    	bool operator>=(vektor const& envek);
    
    	//Operatorer
    	vektor operator+(vektor const& envek);
    	vektor operator-(vektor const& envek);
    	vektor operator*(long double const& tal);
    	vektor operator/(long double const& tal);
    //	vektor operator%(long double const& tal);
    
    	//Return funktioner
    	long double retStartX() { return startX; };
    	long double retStartY() { return startY; };
    	long double retEndX() { return endX; };
    	long double retEndY() { return endY; };
    	long double retMag() { return Magnetude; };
    	float retHed() { return Heading; };
    
    private:
    	long double startX, startY, endX, endY, Magnetude;
    	float Heading;
    
    	void updateHedOMag();
    	void updateeXOeY();
    	void fixavinkel();
    
    };
    You have to excuse that i comment my code with a mix of Swedish and English.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    It may be something relatively simple, like: since UpdateSim class contains a vektor object, the vektor class needs to be declared before the UpdateSim class, OR you need to have a forward declaration telling the compiler/linker that the vektor class is really there, even if it hasn't been seen already.
    You're only born perfect.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    You need to implement the default constructor. Did you implement any of the vektor functions in a source file? If yes, then you might have forgotten the default constructor, or you might not be compiling that source file, or you might not be linking to the compiled object file. If no, then you need to implement those functions to get it to link.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    2
    Thanks i got it. I had forgotten to declare the default constructor.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Good. By the way, technically speaking, you didn't forget to declare the default constructor (it's declared in the header you posted), you just forgot to define it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 05:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21