Undefined Reference to class::class



  • Ich komm irgendwie nicht auf den Konstruktor oder so, keine Ahnung wieso das nicht gefunden wird. Bin für jede Hilfe dankbar.

    Fehlermeldung:

    /tmp/ccwpT6zY.o: In function `main':
    /home/xatrixx/Desktop/Programmierung/Turrican/./main.cc:10: undefined reference to `turrican::turrican()'
    collect2: ld returned 1 exit status
    

    main.cc

    #include <iostream>
    #include "turrican.h"
    
    using namespace std;
    
    int main(int ac, char **av)
    {
    
    turrican t;
    
    return 0;
    }
    

    turrican.h

    #ifndef _TURRICAN_
    #define _TURRICAN_
    
    #define X 800
    #define Y 600
    
    class turrican
    {
    
    	public:
    	turrican();
    	turrican(int xcoord, int ycoord);
    	void move_left();
    	void move_right();
    	void jump();
    	void shoot();
    	void take();
    	void transform();
    	void damage();
    	void die();
    
    	private:
    	int x; //X Position
    	int y; //Y Position
    	int position[X][Y]; //Array of Position
    	int shoottype; // Schusstypen: 0 = Standard
    	int status; //0=lebt, 1=rad, 2=tot
    
    };
    
    #endif
    

    turrican.cc

    #include <iostream>
    #include "turrican.h"
    
    turrican::turrican()
    {
    x=X/2;
    y=Y/2;
    shoottype=0;
    status=0;
    }
    
    turrican::turrican(int xcoord, int ycoord)
    {
    x=xcoord;
    y=ycoord;
    }
    


  • Hast du Turrican.cpp nicht mitgelinkt?

    #if !defined(TURRICAN_HPP__INCLUDED)
    #define TURRICAN_HPP__INCLUDED
    
    #if (_MSC_VER >= 1300)
    #pramga once
    #endif // (_MSC_VER >= 1300)
    
    class turrican
    {
        enum shoottype { normal = 0 } m_shoottype;
        int m_x;
        int m_y;
        enum state { alive, rad, dead } m_state;
    
    public:
        turrican(int x = 400, int y = 300)
            : m_x(x), m_y(y), m_shoottype(normal), m_state(alive)
        {}
    
    public:
        void move_left();
        void move_right();
        void jump();
        void shoot();
        void take();
        void transform();
        void damage();
        void die();
    };
    
    #endif // TURRICAN_HPP__INCLUDED
    
    #include <iostream>
    #include "Turrican.hpp"
    
    int main()
    {
        turrican inst;
    }
    

    .



  • Keine Ahnung was du meinst, das Programm übersetz ich mit:

    g++ -o main -Wall -g ./main.cc

    Wenn ich in der main turrican.h include, müsst das doch reichen, oder nicht?



  • Du musst noch turrican.cc dazulinken:

    g++ -o main -Wall -g ./main.cc ./turrican.cc


Anmelden zum Antworten