Bitte um Hilfe:error LNK2019: unresolved external symbol(c++ probleme)



  • i have designed the following base class IntArray and derived class IntArrayRC;

    -------------------------------------------------------------
    class IntArray definition and its implementation
    -------------------------------------------------------------

    class IntArray{

    public:

    IntArray( int *myarray, int array_size );
    int size() const { return _size; }

    protected:
    int _size;
    int *ia;

    };

    --------------------------------------------------------------

    #include "IntArray.h"
    #include <iostream>
    extern "C"
    {
    #include <cassert>
    }
    using namespace std;
    IntArray::IntArray(int *myarray, int array_size)
    {
    //set data members.
    _size = array_size;
    ia = new int [ _size ];

    //copy data members.
    for( int ix = 0; ix < _size; ++ix )
    ia[ ix ] = myarray[ ix ];
    }
    -----------------------------------------------------------------------------
    class IntArrayRC definition and implementation
    ------------------------------------------------------------------------------
    #include "IntArray.h"

    class IntArrayRC: public IntArray {

    public:

    IntArrayRC( int *iar, int sz );

    private:
    void check_range( int );

    };
    ------------------------------------------------------------------------------
    #include "IntArrayRC.h"
    #include "IntArray.h"
    using namespace std;

    extern "C"
    {
    #include <cassert>
    }

    ~IntArrayRC::IntArrayRC( const int *iar, int sz )
    : IntArray( iar, sz ) {}~

    ------------------------------------------------------------------------------
    main.cpp
    -----------------------------------------------------------------------------

    #include "IntArray.h"
    #include "IntArrayRC.h"
    #include "IntArray.cpp"
    #include <iostream>
    extern "C"
    {
    #include <cassert>
    }
    using namespace std;

    extern void swap( IntArray &, int, int );

    int main(void)
    {
    int ar[ 4 ] = { 0, 110, 2, 3333 };

    IntArray ia1( ar, 4 );
    IntArrayRC ia2( ar, 4 );

    system("PAUSE");
    return EXIT_SUCCESS;
    }

    running:

    Compiling...
    main.cpp
    Generating Code...
    Skipping... (no relevant changes detected)
    IntArray.h
    Linking...
    LINK : C:\Users\fengyahui\Documents\Visual Studio 2008\Projects\C_plus_plus_primer_study\Debug\C_plus_plus_primer_study.exe not found or not built by the last incremental link; performing full link
    main.obj : error LNK2019: unresolved external symbol "public: __thiscall IntArrayRC::IntArrayRC(int *,int)" (??0IntArrayRC@@QAE@PAHH@Z) referenced in function _main
    C:\Users\alex\Documents\Visual Studio 2008\Projects\C_plus_plus_primer_study\Debug\C_plus_plus_primer_study.exe : fatal error LNK1120: 1 unresolved externals


  • Mod

    Ich vsetehe nicht was zu welcher Datei gehört in Deinem Posting.

    Auffällig:
    1. Du machst einen #include der IntArray.cpp. Die gehört einfach in das Projekt eingefügt
    2. Gleiches gilt vermutlich für die IntArrayRC.cpp, die nicht zum Projekt gehört.



  • Der Konstruktor ist als

    IntArrayRC( int *iar, int sz )

    deklariert und die Implementierung als

    IntArrayRC::IntArrayRC( const int *iar, int sz )

    Da ist nen const zuviel/zuwenig


Anmelden zum Antworten