i have class Sum_class defines as...
the problem is that the destructor will be invoked soon after the constructor is called as the objects scope are localised within the loop...
is there any way out so that i can declare objects dynamically using vector (as many as want)...and prevent the call of destructor.....
Code:
class Sum_class
{
private:
int data_member1;
char* data_member2;
public:
Sum_class()
{ data_member2 = new char;
}
~Sum_class()
{ cout<<"Destructor called";
delete data_member2;
data_member2=0;
}
void get_input(void)
{
code.....
}
void show_output(void)
{
code....
}
};
int main()
{
vector<Sum_class> object;
char CONTINUE ='y';
while(CONTINUE!='n' || CONTINUE!='N')
{
object.push_back(Sum_class()); // this will invoke constructor
....
code...
}
....
code...
return EXIT_SUCCESS;
}
is there any way out so that i can declare objects dynamically using vector (as many as want)...and prevent the call of destructor.....
Comment