Thread: vector - left of .push_back must have class/struct/union type

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    121

    vector - left of .push_back must have class/struct/union type

    Embarassing- I'm trying to create a vector and use a for-loop to push_back values into it. I included #include<vector> header, and #include<algorithm>, but it is telling me that for myVector.push_back(1), for example, "left of .push_back must have class/struct/union type. I can't post the code here, I'm on my BlackBerry. What could I be forgetting? I know it's probably a little detail I forgot

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Check how you declared myVector.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Quote Originally Posted by pianorain
    Check how you declared myVector.
    vector<int> myVector();

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Nothing wrong with the above vector declaration, right?

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Wrong

    Remove the parenthesis.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Muito obrigado, Mario, tu salvaste a minha vida! I promised a simple program to my buddy, and I didn't want to admit that I couldn't do it because of such a small thing. Had forgotten that the parenthesis were only for initializing with data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  3. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  4. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 09:51 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM