Thread: vector of classes

  1. #1
    Registered User
    Join Date
    Jul 2008

    vector of classes

    Am getting an error message while trying to create a vector of class objects.

    	std::vector<cannon> cballs;
    	cballs.insert(cballs.begin(), new cannon(5*ballNo,90,5));
    error C2664: 'class cannon *__thiscall std::vector<class cannon,class std::allocator<class cannon> >::insert(class cannon *,const class cannon &)' : cannot convert parameter 2 from 'class canno
    n *' to 'const class cannon &'
    Reason: cannot convert from 'class cannon *' to 'const class cannon'
    No constructor could take the source type, or constructor overload resolution was ambiguous

  2. #2

    Join Date
    Apr 2008
    From the looks of that error message, it seems you don't need the word 'new'.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    Yes, it's the new that's wrong.
    std::vector<cannon> cballs;
    You have a vector of cannon objects, but you're using new which is trying to insert cannon* pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM