Sign in to follow this  

why dose this work?

This topic is 4596 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
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

This topic is 4596 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this