Hi all

A teacher of mine told me that when an object of a class is created then six things are created.He didn't told me which.I know the obvious 4 things
1)Copy constructor
2)Copy asignment
3)Constructor
4)Deconstructor

I don't know anything else?Do you have ab\ny idea?I searched everywhere but i didn;t find anything! Thank you for your time!

I know the obvious 4 things

All four of which are not strictly correct. I suspect your teacher is oversimplifying to the point of being wrong, in which case your best bet is to ask him what the six things are and why. I could speculate about the other two things that are created, but it would just be speculation.

Would you mind to express your speculations?I suspect that one other item is the virtual table

A virtual table would be one of my speculations. Base class sub objects would be another. Hell, he might even mean the object itself, or the this pointer.

Well i haven't thougth about the base class sub object.Thanks anyway you gave me feed for my research on the net :D

A teacher of mine told me that when an object of a class is created then six things are created. ...
1)Copy constructor
...

Copy constructors etc. are synthesized (if required) by the compiler at compile-time.

Objects are created at runtime.

Hi all

A teacher of mine told me that when an object of a class is created then six things are created.He didn't told me which.I know the obvious 4 things
1)Copy constructor
2)Copy asignment
3)Constructor
4)Deconstructor

I don't know anything else?Do you have ab\ny idea?I searched everywhere but i didn;t find anything! Thank you for your time!

Only two those things are necessary when a class is created(constructor, deconstructor). Not all classes have Copy Constructors nor Copy assignment operators.

Same thing with VTs, only inherited classes whose base class has at least one virtual function has those. I don't understand your professors comment. Did he mean "Things that may be created?" In which case, Base class and VT may fill the last 2 spots. As stated above, it's speculation however. Your teacher may have meant the member functions. The statement is much too obscure.

When an object is create, that is, at run-time, all the methods already exist (they are created at compile-time). Those 4 answers make no sense that way. If you create an object, why would it need to create its constructors? It can only be created once. Either the question is wrong (not termed properly) or you are back to square one because none of those answers would be correct.

When an object is created (at run-time) it creates its base class(es), its data member(s), and the new entries of its virtual table if it has/needs one. If you stretch the definition of "create an object" to "object = new Class;", then you might say that an "area in memory is created" for the object and "an entry for that area of memory is created by the heap". That would bring the count to 5, but that is stretching it (and I doubt that your prof meant to involve dynamic allocation and the heap in the answer).

Ask your prof... I suspect the terminology is a bit sloppy because taken to the word I cannot possibly think of 6 things that are created at run-time when the constructor of a class is invoked (and knowing exactly what gets created when a constructor is invoked is pretty elementary and necessary knowledge for an experienced programmer like me, and the others who posted here).

Actually sory for not been so acurate,he told as if you declare an empty class and then inside main you create an object of this class what is created? Well indeed the question is a litle bit obscure,the teacher told as find it yourself and i just ask in case he ask it in the upcoming examinations.Well maybe i am wrong but i can't understand either his point nor anyone of f the student of my class.

if you declare an empty class and then inside main you create an object of this class what is created?

A single byte. :) In the case of a class with no data members, the compiler will allocate sufficient space to give the object an address. On a side note, because there are no data members and no base classes, all of the special member functions are completely trivial and thus not generated implicitly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.