Advertisement Jump to content
Sign in to follow this  
setaglib

why dose this work?

This topic is 4998 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 all, I know this is going to sound stupid but why does the following code not work
 template<typename type>
 type* foo<type>::get() 
 {
   return (type*)bar;
 }

It'll give me an error when I assign that to a pointer. However, if I were to make it constant like this:
 template<typename type>
 type* foo<type>::get() const
 {
    return (type*)bar;
 }

It works... I don't mind using that code I was going to change it to something like that anyway. But why does the first method not work!?

Share this post


Link to post
Share on other sites
Advertisement
Neither will compile since "bar" is undefined. And even then, the "const" in your second case won't compile, since it can only be applied to a class method (which is obviously not the case here, since you posted no classes).

Post more code.

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!