About Store Forum Documentation Contact



Post Reply 
EE::Map inside of a struct
Author Message
Driklyn Offline
Member

Post: #1
EE::Map inside of a struct
How do you use EE::Map inside of a struct? For instance, if you take the Map tutorial and just wrap the map variable inside of a struct, the map can no longer find the Create or Compare functions. Not sure why and I can't find an explanation on this site or Google.

Code:
struct Test
{
    Map<Key,Data> map(Create,Compare,NULL);
};

Produces these errors:

Code:
error C2061: syntax error : identifier 'Create'
Error: function 'Create' is not a type name
04-20-2011 08:09 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #2
RE: EE::Map inside of a struct
Well it can work if you init the map in the constructor if thats what u mean:


PHP Code:
struct Test
{
static 
Bool Create(Object &objint &keyPtr user)
    {
        return 
true;
    }

    static 
Int Compare(int &aint &b)
    {
        if(
a<b)return -1;
        if(
a>b)return +1;
        return  
0;
    }

 
Map<Key,Datamap(Create,Compare,NULL);
}


Test::Test() : map(Test::Create,Test::Compare,NULL)
{



There is always evil somewhere, you just have to look for it properly.
04-20-2011 09:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #3
RE: EE::Map inside of a struct
Unfortunately, this does not work for me. Gives the same two errors as above (these errors also apply to Compare as well, obviously) and these:

Code:
EE::Map<Key, Data> Test::map(<error-type>, <error-type>, <error-type>)
Error: "map" is not a nonstatic data member or base class of class "Test"

Still unable to find Create and Compare functions.
(This post was last modified: 04-20-2011 10:23 PM by Driklyn.)
04-20-2011 10:20 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #4
RE: EE::Map inside of a struct
did you add static to the create/compare functions?

There is always evil somewhere, you just have to look for it properly.
04-20-2011 10:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #5
RE: EE::Map inside of a struct
They always were static.
04-20-2011 10:41 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #6
RE: EE::Map inside of a struct
Yes but u need to set: Map<int, TestObj> map; in the header file and the Test::Test() : map(Test::Create,Test::Compare,NULL) in the cpp file...

This should work tho...

There is always evil somewhere, you just have to look for it properly.
04-20-2011 10:56 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #7
RE: EE::Map inside of a struct
Eureka! That did the trick.

Code:
struct Test
{
    // Create and Compare functions...

    Map<Key,Data> map; // (Create,Compare,NULL); <== leave off
    Test();
};

Test::Test() : map(Test::Create,Test::Compare,NULL) {}

Thanks!
(This post was last modified: 04-20-2011 11:12 PM by Driklyn.)
04-20-2011 11:11 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #8
RE: EE::Map inside of a struct
great smile

There is always evil somewhere, you just have to look for it properly.
04-20-2011 11:13 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply