I'm trying to write a C++ program that uses some compound structs and vectors, and I'm getting a compile time error: multiple types in one declaration.

Here's the form my code's in:

#include <vector>
using namespace std;

struct Struct2 {
    int value1;
    int value2;
}; // end Struct2

struct Struct1 {
    int value;
    vector<Struct2> vec;
}; // end Struct1

class MyClass {
public:
    // constructor and various methods

private:
    vector<Struct1> classVec;
}; // end MyClass

That error points to the line where "classVec" is declared. I've tried some things like adding empty constructors to the structs, but that didn't change anything. Any pointers would be appreciated.

Thanks!

Recommended Answers

All 4 Replies

works ok for me. your problem must be something else. what compiler? what are the errors?

That's the only error I'm getting:

error: multiple types in one declaration

I just realized though that the error is on the ending bracket of "MyClass", not the declaration of "classVec". I'm using g++ to compile.

Dang it, I'm an idiot. I didn't have a semicolon at the end of my second struct declaration. Yeah, that error makes sense to me now. Sorry for taking up your time, and thanks for the quick reply.

Now if I can figure out how to close this thread, both of my problems will be solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.