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 e, int 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");
}
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.
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
Re: Problem with the constructor
Quote:
Originally Posted by
jacksparrow
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)
{}