Jump to content
  • Advertisement
Sign in to follow this  
jpbb

Compilation Error

This topic is 4307 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, I have two methods like so:
using namespace test;

void AudioManager::ScheduleLoad( Sound *pSound );

void Sound::Load()
{

    // snip

    g_pAudioManager->ScheduleLoad( this );

    // snip

}
This code gives this error at compile time: error C2664: 'void test::AudioManager::ScheduleLoad(Sound *)' : cannot convert parameter 1 from 'test::Sound *const ' to 'Sound *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Does anyone know why this doesn't compile? I kknow that this is const, but changing the Scheduling method to void AudioManager::ScheduleLoad( const Sound *pSound ); just causes an error which says that Sound *const cannot be converted to const Sound * Any help would be very much appreciated, thanks.

Share this post


Link to post
Share on other sites
Advertisement
Your this pointer is apprently of type Sound * const, which would happen if your Load method is a const method (in short, you guaranteed that the method would not change the object pointed by this).

Are you sure the method is non-const?

Share this post


Link to post
Share on other sites
100% sure. The declaration loks like this:

class AudioManager : public IAudioManager
{
public:

void ScheduleLoad( Sound *pSound );

};

class Sound : public ISound
{
public:

bool Load();

};


Obviously I have removed all of the other method, if it makes a difference.

Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpbb
cannot convert parameter 1 from 'test::Sound *const ' to 'Sound *'


By chance, do you happen to have a class Sound outside of namespace test? The error message seems to be saying that you are trying to pass a test::Sound* while the function wants a ::Sound*.

Quote:
Original post by ToohrVyk
Your this pointer is apprently of type Sound * const


Sound * const would mean a constant pointer to Sound, not a pointer to a const Sound. this acts like a constant pointer in that it can not be assigned to, so that is probably the reason why the error message gives the type as Sound* const. Had Load been const, the type of this would have been const Sound*.

Share this post


Link to post
Share on other sites
Quote:
Original post by Reckoner
Sound * const would mean a constant pointer to Sound, not a pointer to a const Sound. this acts like a constant pointer in that it can not be assigned to, so that is probably the reason why the error message gives the type as Sound* const. Had Load been const, the type of this would have been const Sound*.


I guess this confirms once again how much I hate C types. You are, of course, completely right.

Share this post


Link to post
Share on other sites
Quote:
Original post by Reckoner
Sound * const would mean a constant pointer to Sound, not a pointer to a const Sound. this acts like a constant pointer in that it can not be assigned to, so that is probably the reason why the error message gives the type as Sound* const. Had Load been const, the type of this would have been const Sound* const.


Fixed, if I'm thinking clearly. :) The this-pointer itself is const whether or not the pointed-at thing is const.

(Of course, it *should* be a reference, anyway, but that's the language we live with :( )

Share this post


Link to post
Share on other sites
Fixed.

I was using a few forward class declarations, and hadn't put them inside the namespace.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Fixed, if I'm thinking clearly. :) The this-pointer itself is const whether or not the pointed-at thing is const.


Sorry, I didn't express myself clearly. The standard says (9.3.2.1) that the type of this in a non-const member function of X is X*, and in a const member function const X*. But it is also not an lvalue, so it acts like an X* const in most (but not all) cases, and appears to be reported as such by Visual C++.

[Edited by - Reckoner on January 29, 2007 8:41:52 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!