Issue creating a vector of a struct in C++

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2005
Posts: 9
Reputation: Bidromicles is an unknown quantity at this point 
Solved Threads: 0
Bidromicles Bidromicles is offline Offline
Newbie Poster

Issue creating a vector of a struct in C++

 
0
  #1
Apr 29th, 2007
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:
  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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,615
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

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

 
0
  #2
Apr 29th, 2007
works ok for me. your problem must be something else. what compiler? what are the errors?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 9
Reputation: Bidromicles is an unknown quantity at this point 
Solved Threads: 0
Bidromicles Bidromicles is offline Offline
Newbie Poster

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

 
0
  #3
Apr 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 9
Reputation: Bidromicles is an unknown quantity at this point 
Solved Threads: 0
Bidromicles Bidromicles is offline Offline
Newbie Poster

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

 
0
  #4
Apr 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 9
Reputation: Bidromicles is an unknown quantity at this point 
Solved Threads: 0
Bidromicles Bidromicles is offline Offline
Newbie Poster

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

 
0
  #5
Apr 29th, 2007
Now if I can figure out how to close this thread, both of my problems will be solved...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC