user14842715
user14842715

Reputation:

Destructor with copy constructor

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 :)

Upvotes: 0

Views: 98

Answers (1)

MikeCAT
MikeCAT

Reputation: 75062

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
}

Upvotes: 1

Related Questions