Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Simple testing

Name: Anonymous 2009-01-20 10:48

Sup /prog/, where's the mistake?

class ArrayBox
{
public:

int numbers[9];
//functions
};

int main()
{
ArrayBox ab;
ab.numbers[] = {12, 23, 43, 4, 15, 61, 79, 18, 9, 5};
}


u2.cpp: In function "int main()":
u2.cpp:94: Error: expected primary-expression before "]" token
u2.cpp:94: Error: expected primary-expression before "{" token
u2.cpp:94: Error: expected ";" before "{" token


isn't that the right syntax to fill an array? I'm confused.

Name: Anonymous 2009-01-20 11:49

>>7
As a note, reserve is NOT optional if you use the [] operator to add elements, it's only optional if you use push_back(), because push_back() automatically reserves more space.

Although it's more efficient to reserve space for 10 elements and then use push_back to add the numbers.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List