![]() |
|
#1
|
|||
|
|||
Create Vector To Hold Object?Hi everyone!
I have some Lab exercises to do, and well, simply i am stuck. Can i have some help getting me started, understanding all this? thanx! I have a Transaction class; ----------------------------------------------------------------- CPP / C++ / C Code:
i have to complete the constructor, i am not sure how to approach this... the other part to my exercise is to create 20 sample records (with code provided from this file "http://www.vtr.net/~mwb/c++/part21b.cpp" )and store them in a vector named trans (not necessary to read the data from a text file) how do i start???? gracias amigos! |
|
#2
|
|||
|
|||
|
To complete the constructor, you simply assign the arguments that are sent to the Transaction() function/constructor, to the private members of the class. I.e.
A constructor is run to set up the class - so that the other functions have something to work with. All the objects variables would be undefined, unless there's a constructor to set them up. Here's one or 2 to get you started: CPP / C++ / C Code:
Question 2: A vector is a dynamic array. Normal arrays have a fixed size - vectors can expand as required. Vectors are part of the C++ STL (Standard Template Library) - and are easy to use. You create a vector and add a Transaction as follows: CPP / C++ / C Code:
GF |
|
#3
|
|||
|
|||
|
thanks for the definitions, i had them kinda mixed up....its getting clearer!
is this ok then? CPP / C++ / C Code:
the vector...do i create a new class? or do i enter in the same transaction class?? i am not sure how to test this either? to make sure i am doing ok.. thanks again GF. |
|
#4
|
|||
|
|||
|
You're forgetting your semicolons - the compiler will tell you that anyway.
The vector class is made for you already. Just include <vector> and use away. You have the Transation class coded yourself, then you pass it to the vector as I've mentioned above. I suggest you look up some books on C++ to get comfortable with the syntax. GF |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gxx linker accepts only 7 object files | danielxs66 | CPP / C++ Forum | 1 | 12-Dec-2003 09:27 |
| Can't seem to create db | Tigress7 | MySQL / PHP Forum | 3 | 19-Aug-2003 09:19 |
| How do I access an object from inside another object? | JdS | MySQL / PHP Forum | 5 | 10-Jun-2003 08:51 |
| 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