Thread: Vectors work when they want to.

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    141

    Vectors work when they want to.

    Makes 0% sense.

    I understood and still understand how to make vectors, but now it doesn't work, what the hell?

    push_back is acting like a dick, it gives me an error when I try to call it, even though it's been called like this before, pfft.. It's weird.

    Code:
    #include <string>
    #include <vector>
    
    std::vector<int> vec;
    Yes we know this works, and push_back works.

    Code:
    
    
    vec.push_back(12);

    But this doesn't work, and I even used vectors before, and even used this, now it doesn't work. Lol C++ is REEEEAALLY GREAT
    Last edited by bobbelPoP; 07-28-2008 at 06:50 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Post the errors you're getting and tell us how it's "not working".

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    std::vector<int> vec();

    Very rarely does a language "act like a d***"

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    141
    Code:
    1>(6) : error C2143: syntax error : missing ';' before '.'
    1>(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>(6) : error C2371: 'test' : redefinition; different basic types
    1>        (4) : see declaration of 'test'

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    The code that's failing to compile would help, too.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by medievalelks View Post
    The code that's failing to compile would help, too.
    It was in the OP..

    Fine..
    Code:
    #include <string>
    #include <vector>
    
    std:: vector<int> vec;
    
    vec.push_back(12);

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    The compiler is complaining about something named "test". I don't see that in the code.

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by medievalelks View Post
    The compiler is complaining about something named "test". I don't see that in the code.
    That's because I'm changing code around. :P Basically, it's the same thing every time, regardless of what the variable name is.

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    141
    Wow.. Even copy-pasted code from cppreference.com doesn't even work. wtf?

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    There is a space between your declarations std:: and the vector object
    Double Helix STL

  11. #11
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by swgh View Post
    There is a space between your declarations std:: and the vector object
    So? It worked liked that before so it doesn't matter. And others work aswell so meh.

  12. #12
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Just a number '12' can be seen as a 'const int' , in which case your specialisation is not correct. Try to define an int equal to 12, and then push back that int. Although I don't suspect this from being the error...
    Code:
    std::vector<int> vec();
    this shouldn't make any difference...

  13. #13
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Post the complete piece of code you're trying to compile, not just snippets. And if you're copy-pasting code, you have to be careful that you don't get any hidden HTML chars in it.

  14. #14
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by MarkZWEERS View Post
    Just a number '12' can be seen as a 'const int' , in which case your specialisation is not correct. Try to define an int equal to 12, and then push back that int.
    Code:
    std::vector<int> vec();
    this shouldn't make any difference...
    Neither std::vector<int> vec(); nor const work.

  15. #15
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by indigo0086 View Post
    std::vector<int> vec();
    That's a declaration of a function named vec that takes no arguments and returns a std::vector<int>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  3. Adding vectors ??
    By Hussain Hani in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2006, 03:03 AM
  4. Axis based on 2 Vectors
    By durban in forum Game Programming
    Replies: 1
    Last Post: 11-10-2005, 04:38 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM