469,072 Members | 1,816 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

Error in program using vectors, list, and user defined class

Hi guys,
I'm getting an error i cannot figure. Here is my code

Header file
-------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. #ifndef Clock_H
  2. #define Clock_H
  3.  
  4. #include <vector>
  5. #include <list>
  6.  
  7. class Clock {
  8.  
  9.     public:
  10.         //Constructor
  11.         Clock(int h, int s, int e);
  12.  
  13.         //Get the next and previous configs of the current config
  14.         vector<vector<int> > getNeighborConfigs(vector<int> config);
  15.  
  16.         //Is the current Config a solution?
  17.         bool isSolution(vector<int> sol);
  18.  
  19.         //Gets the goal config
  20.         int getSolution();
  21.  
  22.         //Sets the current step # of the solution
  23.         void setStep(int val);
  24.  
  25.         //Displays the solution
  26.         void display(list<vector<int> > dList);
  27.  
  28.     private:
  29.         int hours;
  30.         int start;
  31.         int end;
  32.         int stepNumber;
  33.  
  34. };
  35. #endif
  36. ------------------------------------------------------------------------------------------
  37. CPP file
  38. #include <vector>
  39. #include <list>
  40. #include <queue>
  41. #include <iostream>
  42. #include "Clock.h"
  43.  
  44. /**
  45. * Constructor for Clock class that takes in the hours, start time 
  46. * and goal time. Uses sub-object construction
  47. */
  48.  
  49. Clock::Clock(int h, int s, int e) :
  50.     hours(h), start(s), end(e) {
  51. }
  52.  
  53. /**
  54. * Get the next and previous configs of the current config
  55. * Stores it in a vector of vector of ints
  56. */
  57.  
  58. vector<vector<int> > Clock::getNeighborConfigs(vector<int> config) {
  59.     vector<vector<int> > configs; //stores the next and previous configs
  60.     vector<int> next; //stores the next config
  61.     vector<int> previous; //stores the previous config
  62.  
  63.     int num1=(config.front() + 1)%hours;
  64.     int num2=(config.front() -1)%hours;
  65.  
  66.     if(n1 == 0) {
  67.         n1 = hours;
  68.     }
  69.     if(n2 == 0) {
  70.         n2 = hours;
  71.     }
  72.     next.push_back(num1);
  73.     previous.push_back(num2);
  74.  
  75.     configs.push_back(next);
  76.     configs.push_back(previous);*/
  77.  
  78.     //return configs;*/
  79. }
  80.  
  81. /**
  82. * Is the current Config a solution?
  83. */
  84.  
  85. bool Clock::isSolution(vector<int> sol) {
  86.     for(int i=0; i<sol.size(); i++) {
  87.         if(sol[i]==end) 
  88.             return true;
  89.     }
  90.     return false;
  91. }
  92.  
  93. /**
  94. * Gets the goal config
  95. */
  96.  
  97. int Clock::getSolution() {
  98.     return end;
  99. }
  100.  
  101. /**
  102. * Sets the current step # of the solution
  103. */
  104.  
  105. void Clock::setStep(int val) {
  106.     stepNumber=val;
  107. }
  108.  
  109. /**
  110. * Displays the solution
  111. */
  112.  
  113. void Clock::display(list<vector<int> > dList) {
  114.     cout << "Count: " << count << endl;
  115.     cout << "The solution is: " << endl;
  116.     while(!dList.empty()) {
  117.         vector<int> vec = dList.front();
  118.         cout << vec[0] << endl;
  119.         dList.pop_front();
  120.         cout << endl;
  121.     }
  122. }
I get this error at compilation
Expand|Select|Wrap|Line Numbers
  1. Clock.h:24: error: ISO C++ forbids declaration of ‘vector’ with no type
  2. Clock.h:24: error: expected ‘;’ before ‘<’ token
  3. Clock.h:27: error: ‘vector’ has not been declared
  4. Clock.h:27: error: expected ‘,’ or ‘...’ before ‘<’ token
  5. Clock.h:36: error: ‘list’ has not been declared
  6. Clock.h:36: error: expected ‘,’ or ‘...’ before ‘<’ token
  7. Clock.cpp:34: error: expected constructor, destructor, or type conversion before ‘<’ token
Any help would be appreciated,
Thanks
Sep 29 '07 #1
2 2841
Never mind guys, i figured it out...AFTER a couple of hrs!!
Sep 29 '07 #2
RRick
463 Expert 256MB
Hhhmmm, did you forget the std:: before vector? I have been burned too many times with that error.

One way around that problem is to add the following after your STL headers. Now you can write "vector" instead of "std::vector".
Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. #include <list>
  3. using namespace std;
  4.  
Sep 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Ed | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.