Thread: Insanely difficult vector weird error pizza

  1. #1
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656

    Insanely difficult vector weird error pizza

    Code:
    #include <iostream>
    #include <vector>
    using std::cout;
    using std::vector;
    
    int main() {
    	vector <int> _v1;
    	vector <int> _v2;
    
    	_v1.push_back(3);
    	_v1.push_back(10);
    	_v1.push_back(33);
    
    	for(int x=0; x<_v1.size(); x++) {
    		cout<< _v1[x] << " ";
    	}
    
    	if(!_v1.empty()) {
    		_v1.clear();
    	}
    
    	_v2.push_back(10);
    	_v1.push_back(10);
    	if(_v1 == _v2) {
    		_v1.push_back(20);
    	}
    
    	_v1.switch(1, 2);		// <---- DARN ERORS!!  GGRRAAHH!!
    	for(int y=0; y<_v1.size(); y++) {
    		cout << _v1[y] << " ";
    	}
    	return 0;
    }
    I keep getting this error:
    Code:
    kleid@Shiva:~/Programming/Laboratory$ g++ vectors.cpp
    vectors.cpp: In function `int main()':
    vectors.cpp:28: error: parse error before `switch'

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Rename your function - switch is a reserved word in C++. Perhaps something like, "swap"?

  3. #3
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Mistype! It happens to me all of the time!

    http://www.cprogramming.com/tutorial/stl/vector.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 10:44 PM