![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Initialising arrays with default values in derived classHi,
I am new to C++ having recently migrated from FORTRAN. I am trying to create multiple derived classes each containing various integer or float parameters and 2 arrays, let's call them X and Y, of different sizes (hence different derived classes). X and Y are private data members of the derived class. My problem is that I want to initialise each instance of these derived classes to have default values for XArray and Y, of which X will be overwritten later (using a member function) on the basis of values returned by an external function. I hope this question is not too banal. Thanks in anticipation CPP / C++ / C Code:
Last edited by LuciWiz : 11-Feb-2009 at 03:17.
Reason: Please insert your C++ between [cpp] & ]/cpp] tags
|
|||
|
#2
|
||||
|
||||
Re: Initialising arrays with default values in derived classQuote:
In your Field class, you should utilize its ctor to initialize it to a known good value or state. That is, your members should be initialized to at least zero, if applicable. In your case, they are all POD types. CPP / C++ / C Code:
If this is some form of classroom assignment, I think that the goal here may be to demonstrate that you can't initialize inherited members or arrays in an "initialization list," though I may be wrong. A review of the standard may be a quick way to find out. MxB |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get a handle to a derived class? | Futterama | MS Visual C++ / MFC Forum | 1 | 29-Jan-2007 10:47 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 20:23 |
| Message Class | TransformedBG | C++ Forum | 5 | 29-Nov-2006 22:28 |
| Box Class, need help again :( | TransformedBG | C++ Forum | 7 | 13-Nov-2006 16:11 |
| a tester class and then some. | postage | Java Forum | 1 | 06-May-2006 16:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The