vector and pointer - quickie

This is a discussion on vector and pointer - quickie within the C++ Programming forums, part of the General Programming Boards category; Quick noob Q: This is how i get a draught for P1 and store it under d1 : Code: Draught ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    37

    vector and pointer - quickie

    Quick noob Q:

    This is how i get a draught for P1 and store it under d1 :

    Code:
     Draught * d1 = player1->getDraught(i);
    Now once its gone through my checks i want to store it in my vector - the number of the draught that is, but i get errors saying :

    1: Cannot convert 'Draught *' to 'int' in function
    2: Error E2342 Game.cpp 231: Type mismatch in parameter 'x' (wanted 'const int &',
    got 'Draught *') in function Game::move(Square *,Draught *)

    Code:
     forcedMoves.push_back(d1);

    i kno i ve made a noob mistake... any help??

  2. #2
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    I say that your vector is a vector<int>, but you treat it like a vector<Draught*>. Maybe this? I don't know how your Draught works.
    Code:
    forcedMoves.push_back(d1->draughtNumber);

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,787
    Looks like you are trying to store a Draught* in a vector<int>, so there is a type mismatch.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

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