Jump to content

  • Log In with Google      Sign In   
  • Create Account

initilse array in a constructor?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 the dodger uk   Members   -  Reputation: 148

Like
0Likes
Like

Posted 14 February 2013 - 05:48 PM

class foo()
{
public :
     foo();
     ~foo()

private:
     int mCount;
     int  mData[5];

};

foo::foo():
mCount(0)
{


}
 

 

 

 

how can i use the same type of inilitisation with mData as i do with mCount

 

i know you can do mData() , but this give a warning , and will not let me  inilise it to anything else


Edited by the dodger uk, 14 February 2013 - 06:04 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13581

Like
1Likes
Like

Posted 14 February 2013 - 06:04 PM

You can’t without C++0x.
Even if you wrapped the array inside a structure, you could initialize the structure with an instance of another structure, even a temporary, but inside the constructor of the structure you would have the same problem.
 
 
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 King Mir   Members   -  Reputation: 2000

Like
0Likes
Like

Posted 14 February 2013 - 10:38 PM

On the other hand, with C++11, it's easy to do. The syntax is this:

foo::foo():mData{1,2,3,4,5}{
}

In general {} syntax was designed to be consistent, and can be used in almost all cases, including in place of ().






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS