Is this two ways of instantiating class both acceptable?(My intention is to create CBox on stack instead of heap)
CBox a=CBox(1);
CBox b(2);
Definition of CBox is as followed:
class CBox
{
public:
int abc;
CBox(int var){
abc=var;
}
};
Is this two ways of instantiating class both acceptable?(My intention is to create CBox on stack instead of heap)
CBox a=CBox(1);
CBox b(2);
Definition of CBox is as followed:
class CBox
{
public:
int abc;
CBox(int var){
abc=var;
}
};
Are you new
ing? If so, that object is on the 'heap'.
Are you instantiating an object within a function? If so, that object is on the 'stack'.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.