Jump to content
  • Advertisement
Sign in to follow this  
IronHawk

Problem In Array::find With A 'const' Param

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

Hello!

 

I'm getting a compile error on searching for an item index in the array when I pass the const value to find().

 

For example it's impossible to compile class like this:

class CDataHolder {
    private array<CData@> m_arr;

    int32 getIndex(const CData@ hData) const {
        return m_arr.find(@hData);  // <<<<<<< Compile error
    }

    ...
}

The error message is: No matching signatures to 'array::find(const CData@&) const'

 

But in add-on the find() function is registered as:

... RegisterObjectMethod("array<T>", "int find(const T&in value) const" ...

So it must work with const parameters too. Or I'm wrong with this?

 

Thanks in advance!

 

Share this post


Link to post
Share on other sites
Advertisement

Hmm. It's not actually a bug. It's a restriction imposed by the language. 

 

You see, the signature "int find(const T&in value) const" registered by the array template, is expanded to "int find(CData@ const &in) const" and not "int find(const CData@&in) const".

 

"CData@ const" means that the handle is const (i.e. cannot be reassigned to a different object), but the object it refers to is not const. 

 

This is why the find method doesn't match when you pass a "const CData@" to the function. A handle to a const object cannot be passed to a function that expects a handle to a non-const object.

 

 

I'll need to think of a way to allow the application to inform when "const T&in" should be expanded to "CData@ const &in" or "const CData@ const &in" so that this situation can be resolved. This will most likely require quite a few changes in the library, so it will take a while.

 

In the mean time, try to see if you can avoid using const CData.

 

 

Share this post


Link to post
Share on other sites

Hello, Andreas!

 

Thank you very much for such a detailed description.

Yes, now I just removed the const and marked the place in code as "required refactoring in future".

 

That would be good of course to have solution from you.

Thanks!

 

Share this post


Link to post
Share on other sites

Well, well. I had clearly overestimated the difficulty of adding this support. Once I identified the path I wanted to go it took no more than a couple of hours to have it working.

 

Give revision 2343 a try. It should solve your issue.

Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites

Hello, Andreas!

 

I updated AS version to "2.31.2 WIP".

And with const all now works properly.

Thank you!

 

Only the JIT compiler crashes on module->Build().

 

Can it be that JIT has some incompatibilities with current AS version?

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!