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 14:20

>>13
template<typename T, size_t N>
vector<T> vector_from_array(T (&a)[N]) {
    return vector<T>(a, a + N);
}


int a[] = { 12, 23, 43, 4, 15, 61, 79, 18, 9, 5};
vector<int> v = vector_from_array(a);

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