473,856 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 3102
brasewel
3 New Member
Never mind guys, i figured it out...AFTER a couple of hrs!!
Sep 29 '07 #2
RRick
463 Recognized Expert Contributor
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::vecto r".
Expand|Select|Wrap|Line Numbers
  1. #include <vector>
  2. #include <list>
  3. using namespace std;
  4.  
Sep 29 '07 #3

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

Similar topics

0
1141
by: Boris | last post by:
The .NET documentation talks about blittable and non-blittable types. While objects of type System::Object* are non-blittable it doesn't say anything about objects of user-defined classes. All the COM interop examples I've seen always return objects of types of the System namespace. But what if you want to return an object of a user-defined managed class? public __gc class A { public: int i; A(int value) : i(value) { }
3
2910
by: Antony | last post by:
When I declared a constant in a class like: public Const attr As ClassB = nothing (ClassB is the user-defined Class) I get the compiler error: Constants must be an intrinsic or enumerated type, not a class, structure, or array type. So how can I declare a constant value of type ClassB in this case? Thanks!
1
1569
by: Vilem Sova | last post by:
I want to use a user-defined object in the 'Add' method to add items to a combo box. The help documentation says that if you use an object in the add method then the object's 'ToString' method is used to obtain the string to display in the combo box. I've added a public property "ToString" to my object that contains the required text to display, but it is not being called to get the required text. The text that is appearing in the combo...
6
3560
by: Dave | last post by:
Is there a way to put some comments in my class designs that will show up in the IDE intellisense so I can add some information about the parameters to be passed to member methods? Thanks in advance for the help. Dave
0
5635
FishVal
by: FishVal | last post by:
Hereby I'm proposing a way of convinient work with properties containing SQL Select statements, particulary RowSource property of ComboBox and ListBox. The usual way is the following. Private Sub Combo1_AfterUpdate() Me.Combo2.RowSource = "SELECT ... FROM ... WHERE Table2.keyID=" & Me.Combo1 & ";" Combo2.Requery
1
2804
by: rolan | last post by:
I am trying to figure out how to store and access an array, which is created inside a function, and needs to be accessed outside the function. My user defined class has set and get functions for 2 values, "value" and "pseudoAddress". "matrix" is of the user-defined class, "*address" is a pointer to the user-defined class I want *address to store the value of matrix, then I want *address to increment by the size of the UD-Class.
3
1535
by: Ed | last post by:
Hi, guys, A big rock blocks my way. I know that to put a user defined class with copy constructor, override operator method, etc, can not be placed into Union. But I have to. I am refactoring an old system with template feature. If there is no way, that means I had to pay additional work to re-implementation.
6
3861
by: Billiska | last post by:
Well, I ask this question because I'm rather familiar with C++ than VB. I've just tried to create a class in VBA and found that I have to write some certain lines every time I want to create a new instance of the class. So, isn't there a way to create a autorun subroutine for initializing a user-defined class?, like "constructor" in C++. Thanks
1
1197
by: nuffnough | last post by:
I have defined two classes with one common field (called code) and several different fields. In class A there is only one instance of any given code as all items are individual. In class B, there may be none, one or many instances of each code, as there can be any number of Bs referring to a single A. I need to make a list of Bs, remove dupes, and then create a list of As that have Bs.
0
9760
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10777
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9530
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7930
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5759
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4573
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4172
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.