codrgi
codrgi

Reputation: 211

make different instances out of the same class?

header of CMain

CSomeClass a

using CSomeClass inside CMain.cpp

a.SomeFunction();
a.m_bVar = SomeVar;

the question is, how do i get a different, second instance of CSomeClass that uses the same varables inside CSomeClass but with their own individual values without the use of new?

i know pSomePointer = new CSomeClass[2];will make a different instance, but is it possible without using new?

Upvotes: 1

Views: 80

Answers (2)

amit
amit

Reputation: 178411

Yes it is,

CSomeClass myObjects[2];

will create two automatically allocated objects.

Upvotes: 0

Konrad Rudolph
Konrad Rudolph

Reputation: 545508

CSomeClass b;

Just declare a new variable.

Furthermore, a probably shouldn’t be defined inside a header but also inside CMain.cpp, just where you need it.

Upvotes: 2

Related Questions