Jump to content
  • Advertisement
Sign in to follow this  
HeWhoDarez

Passing a pointer

This topic is 3621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, Am getting this error: Error 1 error C2664: 'Sprite::Sprite(std::string,int,int,dxManager *)' : cannot convert parameter 4 from 'dxManager **__w64 ' to 'dxManager *' c:\uwe\virtual voices\application\virtualvoices\virtualvoices\virtualvoices.cpp 44 The definition looks like this: Sprite(std::string , int , int, dxManager*); The implementation: Sprite::Sprite(std::string filename, int width, int height, dxManager* dxMan) { RECT scrnRect; scrnRect.left = 0; scrnRect.top = 0; scrnRect.right = width; scrnRect.bottom = height; // create pointer to dxManager //dxMan = NULL; if(!Init(scrnRect)) { MessageBox(NULL, (LPCWSTR)"Unable to Init sprite", (LPCWSTR)"ERROR", MB_OK); } spriteSurface = dxMan->getSurfaceFromBitmap(filename, width, height); if (spriteSurface == NULL) { MessageBox(NULL, (LPCWSTR)"Unable to Create surface from Bitmap", (LPCWSTR)"ERROR", MB_OK); } }; And the call looks like this: Sprite *background = new Sprite("C:/UWE/Virtual Voices/Assets/img/BackGround.tga", 1024, 768, &dxMan); I originally wanted my dxManager to be static (java style) so all members and methods are declared static but have opted to store a local pointer. Any ideas what I am doing wrong? edit: upon re-reading i noticed that there is no return from on the constructor :( my bad - sorry

Share this post


Link to post
Share on other sites
Advertisement
To me it looks like its trying to convert a double pointer to a single pointer.

at the point where you call

Sprite *background = new Sprite("C:/UWE/VirtualVoices/Assets/img/BackGround.tga", 1024, 768, &dxMan)

is dxMan already a pointer? If it is then you dont need the & symbol infront.

Share this post


Link to post
Share on other sites
The call should be like this:

Sprite *background = new Sprite("C:/UWE/Virtual Voices/Assets/img/BackGround.tga", 1024, 768, dxMan);

dxMan is already a pointer so you dont need to take the address of it, if you do you end up with a pointer to a pointer to dxManager, which is why the compiler is complaining.

Share this post


Link to post
Share on other sites
Quote:
Original post by HeWhoDarez
Hi guys,

MessageBox(NULL, (LPCWSTR)"Unable to Init sprite", (LPCWSTR)"ERROR", MB_OK);


In addition to what's mentioned by others, casts are the wrong way to get wide-character strings literals. Use L"Unable to Init sprite" and L"ERROR" instead of using a cast.

Basically, anytime you find yourself needing to write a cast in C++, you should take a step back and ask yourself why you need it. Most of the time, casts in C++ indicate a design error or a coding error. The main place where you need them is in dealing with APIs that are C or COM-based. (For instance the void ** argument to IUnknown::QueryInterface requires a cast, but that's why you should be using a smart pointer class like CComPtr<T> to avoid dealing with the casts.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!