Non-dynamic arrays in a class

I wonder why non-dynamic arrays in a class throw errors upon compilation. (Classes, why you make everything require heaps!?)
They don't. The two have nothing to do with one another.

EDIT:

1
2
3
4
5
class MyClass
{

  int myArray[10];  // this works just fine.
};
Last edited on
But you have to do something like that, and not something like:
1
2
3
4
5
class myclass
{
	int numbers[] = {3,4,1,8};
	//other stuff
};	//end myclass 

iirc that is valid in C++11.
Oh, and if you aren't using C++11 (which I haven't yet!), these would have to be declared in the parametric constructor. I kid you not, I tried defining it in the default constructor, and when I called the parametric constructor and functions, the values were erased!
I tried defining it in the default constructor, and when I called the parametric constructor and functions, the values were erased!


Uhh... yeah. That's because you didn't call the default constructor. The code in the default constructor doesn't get executed unless you default construct an object. When you use a parametric constructor only that constructor executes (read: it won't execute the default constructor).

An object cannot be constructed multiple times.

But I thought we went over this in another thread already. Was that you?
Last edited on
Topic archived. No new replies allowed.