CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    75

    Problem with the constructor

    Hello
    Got This error say's that i should make default constructor even after i did it still come out different error

    before the default constructor i got


    : error C2512: 'pointtype' : no appropriate default constructor available ( LN64)

    after i put default constructor i got this error


    Error 1 error LNK2019: unresolved external symbol "public: __thiscall pointtype::~pointtype(void)" (??1pointtype@@QAE@XZ) referenced in function _main Code.obj


    Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\Hani\ClassPointType\Debug\ClassPointType.exe



    PHP Code:

    #include <iostream>
    using namespace std;

    class 
    pointtype 
    {
    private : 
        
    int x;
        
    int y;

    public : 
    void setx(int);
    void sety(int);
    int getx();
    int gety();
    pointtype();
    pointtype(int e,int f);
    void print();
    ~
    pointtype();

    };

    class 
    circle : public pointtype {
    private: 
        
    float r;

    public: 
        
    void print();
            
    circle(float);
            ~
    circle();
            
    void setr(float);
            
    float getr();
            
    float calculatearea();
            
    float calculatecircumfrance();
    };

    void pointtype::setx int a) { 
        
    x=a;
    }

    void pointtype::sety int d) {
        
    y=d;
    }

    int pointtype::getx () { 
        return 
    x;
    }

    int pointtype::gety () { 
        return 
    y;
    }

    pointtype::pointtype() { 
        
    x=0;
        
    y=0;
    }

    pointtype::pointtype(int eint f) { 
        
    x=e;
        
    y=f;
    }


    void pointtype::print () { 
        
    cout <<x<<y<<endl;
    }


    int main () { 

        
    pointtype c1;
        
    c1.setx (10);
        
    c1.sety (5);
        
    c1.print();

        
    system ("pause");




  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Problem with the constructor

    You did not implement the destructor for pointttype despite declaring it. Anyway, the compiler generated destructor will suffice here, so just remove that destructor declaration.

    By the way, a circle is probably not a pointtype. More likely, a circle has a pointtype that denotes its centre.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2010
    Posts
    75

    Re: Problem with the constructor

    you are right laserlight after i remove it ,, it did work but still not sure if my program is correct its from assignment i will check it later !

    Thanks buddy

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Problem with the constructor

    Quote Originally Posted by jacksparrow View Post
    PHP Code:
        pointtype c1;
        
    c1.setx (10);
        
    c1.sety (5); 
    When I see something like that, I always feel that this is the wrong way. Why not use the constructor that takes x and y? A default constructor along with methods to set members that must be called immediately looks wrong to me.

    Also, in the implementation of the constructors, I would use the initialization list:
    Code:
    pointtype::pointtype(int e, int f) : x(e), y(f)
    {}
    pointtype::pointtype() : x(0), y(0)
    {}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured