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

This is a discussion on vector - left of .push_back must have class/struct/union type within the C++ Programming forums, part of the General Programming Boards category; Embarassing- I'm trying to create a vector and use a for-loop to push_back values into it. I included #include<vector> header, ...

  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,399
    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
    Portugal
    Posts
    7,403
    Wrong

    Remove the parenthesis.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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, 12:56 AM
  2. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 02: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, 08:51 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

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