I want to use destructor in CPP, but, compiler is giving warning "undefined reference".
class trial{
private:
int number;
public:
trial(){};
trial(int num) {
number=num;
};
~trial();
};
Trial class constructor gets value from main function. Help me by telling me whats incorrect in constructor. Thanks in advance:)
It seems you declared the destuctor ~trial();
, but you did not define that.
To define the destructor inside the class declaration, use {}
instead of ;
like ~trial(){}
.
To define the destructor outside the class declaration (inside a source file), write like this:
trial::~trial() {
// do what you want
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.