![]() |
|
#1
|
|||
|
|||
How to Create C++ Objects at Runtime?These are the instructions given to me:
Quote:
Here is my code for my menu: CPP / C++ / C Code:
My lecturer's reply states that he wants me to create the new queue object at runtime. Quote:
He doesn't allow me to have queue q1; before the menu function. He wants me have it as Case 1 in the menu function. I am confused. My compiler doesn't allow me to put Code:
Isn't it impossible for C++ to create objects during runtime in this situation Last edited by LuciWiz : 15-Oct-2004 at 06:02.
Reason: Please insert your c++ code between [c++] [/c++] tags
|
|
#2
|
||||
|
||||
|
I suppose queue is a class you defined, right?
Well, I'm not going to get too deep into this, but consider this *different* approach: CPP / C++ / C Code:
Kind regards, Luci __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein Last edited by LuciWiz : 15-Oct-2004 at 08:05.
|
|
#3
|
||||
|
||||
|
Quote:
Not only is it possible, it is (IMHO) a big part of OOP. The example Luci gave you will create your object at runtime. Even if you don't have a constructor in your class, it will allocate sufficient memory for your object. You probably know this, but referencing members in a pointer to your class is different that referencing members in a static class. CPP / C++ / C Code:
__________________
The best damn Sports Blog period. |
|
#4
|
|||
|
|||
|
A big thanks to our 2 Moderators: LuciWiz and dsmith.
However, other than using queue* q1 in this situation of creating objects during runtime, What are the situations that it's better to use CPP / C++ / C Code:
CPP / C++ / C Code:
I must admit that I'm still an inept user of C++ and OOP. Last edited by LuciWiz : 15-Oct-2004 at 08:32.
Reason: Please use [c] & [/c] tags to enclose your C code - look at those pretty colours :)
|
|
#5
|
||||
|
||||
|
I have two comments on that
HTH. __________________
The best damn Sports Blog period. |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing multiple objects in functions | crystalattice | C++ Forum | 3 | 08-Oct-2004 08:18 |
| Easy way to create tab ctrl | dlaygent | MS Visual C++ / MFC Forum | 1 | 18-May-2004 20:05 |
| Can't seem to create db | Tigress7 | MySQL / PHP Forum | 3 | 19-Aug-2003 09:19 |
| How do I create JavaScript Links? | JdS | Web Design Forum | 8 | 29-Jan-2003 15:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The