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
  4. #include <vector>
  5. #include <list>
  7. class Clock {
  9.     public:
  10.         //Constructor
  11.         Clock(int h, int s, int e);
  13.         //Get the next and previous configs of the current config
  14.         vector<vector<int> > getNeighborConfigs(vector<int> config);
  16.         //Is the current Config a solution?
  17.         bool isSolution(vector<int> sol);
  19.         //Gets the goal config
  20.         int getSolution();
  22.         //Sets the current step # of the solution
  23.         void setStep(int val);
  25.         //Displays the solution
  26.         void display(list<vector<int> > dList);
  28.     private:
  29.         int hours;
  30.         int start;
  31.         int end;
  32.         int stepNumber;
  34. };
  35. #endif
  36. ------------------------------------------------------------------------------------------
  37. CPP file
  38. #include <vector>
  39. #include <list>
  40. #include <queue>
  41. #include <iostream>
  42. #include "Clock.h"
  44. /**
  45. * Constructor for Clock class that takes in the hours, start time 
  46. * and goal time. Uses sub-object construction
  47. */
  49. Clock::Clock(int h, int s, int e) :
  50.     hours(h), start(s), end(e) {
  51. }
  53. /**
  54. * Get the next and previous configs of the current config
  55. * Stores it in a vector of vector of ints
  56. */
  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
  63.     int num1=(config.front() + 1)%hours;
  64.     int num2=(config.front() -1)%hours;
  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);
  75.     configs.push_back(next);
  76.     configs.push_back(previous);*/
  78.     //return configs;*/
  79. }
  81. /**
  82. * Is the current Config a solution?
  83. */
  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. }
  93. /**
  94. * Gets the goal config
  95. */
  97. int Clock::getSolution() {
  98.     return end;
  99. }
  101. /**
  102. * Sets the current step # of the solution
  103. */
  105. void Clock::setStep(int val) {
  106.     stepNumber=val;
  107. }
  109. /**
  110. * Displays the solution
  111. */
  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,
Sep 29 '07 #1
2 3102
3 New Member
Never mind guys, i figured it out...AFTER a couple of hrs!!
Sep 29 '07 #2
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;
Sep 29 '07 #3

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

Similar topics

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) { }
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!
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...
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
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
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.
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.
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
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.
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,...
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,...
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...
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...
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...
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...
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.