Vector syntax errors

This is a discussion on Vector syntax errors within the C++ Programming forums, part of the General Programming Boards category; I have a .h and .cpp for a Room object. Each Room object should contain a vector of Window objects. ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    117

    Vector syntax errors

    I have a .h and .cpp for a Room object. Each Room object should contain a vector of Window objects. When I build the project I get these compiler errors -

    Code:
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(23) : error C2143: syntax error : missing ';' before '<'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(23) : error C2238: unexpected token(s) preceding ';'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(34) : error C2143: syntax error : missing ';' before '<'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(34) : error C2238: unexpected token(s) preceding ';'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(32) : error C2143: syntax error : missing ';' before '<'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(32) : error C2039: 'getWindowVec' : is not a member of 'Room'
    1>        c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.h(10) : see declaration of 'Room'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(32) : error C2143: syntax error : missing ';' before '{'
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(32) : error C2447: '{' : missing function header (old-style formal list?)
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(38) : error C2228: left of '.push_back' must have class/struct/union
    1>        type is ''unknown-type''
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(38) : error C3861: 'getWindowVec': identifier not found
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(43) : error C2228: left of '.push_back' must have class/struct/union
    1>        type is ''unknown-type''
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(43) : error C3861: 'getWindowVec': identifier not found
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(47) : error C2228: left of '.push_back' must have class/struct/union
    1>        type is ''unknown-type''
    1>c:\users\sterling\documents\visual studio 2008\projects\bathroom\bathroom\room.cpp(47) : error C3861: 'getWindowVec': identifier not found
    Here are the .h and .cpp files

    Code:
    #include <vector>
    #include "Window.h"
    #pragma once
    
    #ifndef ROOM_H
    #define ROOM_H
    
    
    class Room
    {
    public:
    	Room(void);
    	Room(int, int);
    	~Room(void);
    
    	int getLength();
    	int getWidth();
    	
    	void turnLightsOn();
    	void turnLightsOff();
    	bool areLightsOn();
    
    	vector<Window>& getWindowVec();
    
    	void addWindow();
    	void addWindow(int, int);
    	void addWindow(Window aWindow);
    
    	
    private:
    	int length;
    	int width;
    	bool lightsOn;
    	vector<Window> windowVec;
    
    };
    
    #endif
    Code:
    #include "Room.h"
    
    Room::Room(void)
    : length(80), width(80){}
    
    Room::Room(int l, int w)
    : length(l), width(w) {}
    
    Room::~Room(void)
    {}
    
    int Room::getLength() {
    	return length;
    }
    
    int Room::getWidth() {
    	return width;
    }
    
    void Room::turnLightsOn() {
    	lightsOn = true;
    }
    
    void Room::turnLightsOff() {
    	lightsOn = false;
    }
    
    bool Room::areLightsOn() {
    	return lightsOn;
    }
    
    vector<Window>& Room::getWindowVec() {
    	return windowVec;
    }
    
    void Room::addWindow() {
    	Window aWindow;
    	getWindowVec().push_back(aWindow);
    }
    
    void Room::addWindow(int l, int w) {
    	Window aWindow(l, w);
    	getWindowVec().push_back(aWindow);
    }
    
    void Room::addWindow(Window aWindow) {
    	getWindowVec().push_back(aWindow);
    }
    I don't see where I am missing semi-colons as the compiler indicates. But maybe it's something else I am not aware of. Can anyone help me out?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,237
    You need std::vector, not vector
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21