944,138 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2294
  • C++ RSS
Apr 29th, 2007
0

Issue creating a vector of a struct in C++

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. #include <vector>
  2. using namespace std;
  3.  
  4. struct Struct2 {
  5. int value1;
  6. int value2;
  7. }; // end Struct2
  8.  
  9. struct Struct1 {
  10. int value;
  11. vector<Struct2> vec;
  12. }; // end Struct1
  13.  
  14. class MyClass {
  15. public:
  16. // constructor and various methods
  17.  
  18. private:
  19. vector<Struct1> classVec;
  20. }; // 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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bidromicles is offline Offline
9 posts
since Sep 2005
Apr 29th, 2007
0

Re: Issue creating a vector of a struct in C++

works ok for me. your problem must be something else. what compiler? what are the errors?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Apr 29th, 2007
0

Re: Issue creating a vector of a struct in C++

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bidromicles is offline Offline
9 posts
since Sep 2005
Apr 29th, 2007
0

Re: Issue creating a vector of a struct in C++

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bidromicles is offline Offline
9 posts
since Sep 2005
Apr 29th, 2007
0

Re: Issue creating a vector of a struct in C++

Now if I can figure out how to close this thread, both of my problems will be solved...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Bidromicles is offline Offline
9 posts
since Sep 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how to set the window position of my console applicaton ?
Next Thread in C++ Forum Timeline: Simple array question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC