About Store Forum Documentation Contact



Post Reply 
STRUCTS
Author Message
cmontiel Offline
Member

Post: #1
STRUCTS
Let's say we have 2 STRUCTS, each one referencing the other. VS displays error C2065.

Code:
STRUCT (ExClass1, GuiObjs)

       static void someFunction()
       {
               ExWindow2.show(); <<<<<<<< error C2065: 'ExWindow2' : undeclared identifier
       }
}ExWindow1;

STRUCT (ExClass2, GuiObjs)

       static void foo()
       {
               ExWindow1.show();
       }
}ExWindow2;

How can I solve it?

IRC: irc.freenode.net
Channel: #Esenthel
(This post was last modified: 05-12-2012 11:07 PM by cmontiel.)
05-12-2012 11:04 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
RE: STRUCTS
Code:
struct ExClass2;

STRUCT (ExClass1, GuiObjs)

       static void someFunction()
       {
               ExWindow2.show(); <<<<<<<< error C2065: 'ExWindow2' : undeclared identifier
       }
}ExWindow1;

STRUCT (ExClass2, GuiObjs)

       static void foo()
       {
               ExWindow1.show();
       }
}ExWindow2;
05-12-2012 11:47 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #3
RE: STRUCTS
This is basic C++. You are trying to reference it before it's declared. Declare your structs before you try to call them. Try using a header.
05-13-2012 12:01 AM
Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #4
RE: STRUCTS
@fatcoder

That doesn't help. Same error.

@Rubeus

Please avoid things like "This is a basic C++" bla bla bla. I tried using a header before posting.

IRC: irc.freenode.net
Channel: #Esenthel
05-13-2012 12:29 AM
Find all posts by this user Quote this message in a reply
PsychoBoy Offline
Member

Post: #5
RE: STRUCTS
It depends on what you need, there are more than one way, if it's static method you don't need object:
Code:
static void someFunction()
       {
               ExClass2::foo();
       }
If it's not static method:
Code:
struct ExClass1 ExWindow1;
struct ExClass2 ExWindow2;

STRUCT (ExClass1, GuiObjs)

       static void someFunction()
       {
               ExWindow2.show();
       }
};

STRUCT (ExClass2, GuiObjs)

       static void foo()
       {
               ExWindow1.show();
       }
};
05-13-2012 02:44 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #6
RE: STRUCTS
Well you need to split the struct into header and cpp file.

header:
PHP Code:
STRUCT (ExClass1GuiObjs)

    static 
void someFunction();
}
ExWindow1;

STRUCT (ExClass2GuiObjs)

    static 
void foo();
}
ExWindow2

cpp:
PHP Code:
void ExClass1::someFunction()
{
    
ExWindow2.show();
}

void ExClass2::foo()
{
    
ExWindow1.show();


There is always evil somewhere, you just have to look for it properly.
05-13-2012 02:45 PM
Visit this user's website Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #7
RE: STRUCTS
None of these solutions works for me, you guys really tested them?
Thank you all anyway.

Here is the code, if someone is interested.

header
Code:
STRUCT (ExClass1, GuiObjs)

    static void someFunction();
};

STRUCT (ExClass2, GuiObjs)

    static void foo();
};

cpp
Code:
// Variable names must be defined here NOT in header or errors will appear.
ExClass1 ExWindow1;
ExClass2 ExWindow2;

void ExClass1::someFunction()
{
    ExWindow2.show();
}

void ExClass2::foo()
{
    ExWindow1.show();
}

IRC: irc.freenode.net
Channel: #Esenthel
05-13-2012 03:39 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #8
RE: STRUCTS
Ain't that the same thing i did? ...lol, ah well im glad u have it working now.

ps: i knew my code was working properly before even testing it and yes to be sure i tested it wink

There is always evil somewhere, you just have to look for it properly.
05-13-2012 03:49 PM
Visit this user's website Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #9
RE: STRUCTS
No, not the same. You defined the variable names in the header. That's causing linker errors. Even if the header has #ifndef #define [] #endif.

IRC: irc.freenode.net
Channel: #Esenthel
05-13-2012 03:55 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #10
RE: STRUCTS
No it wont cause any linking errors, you just have to include it after the Esenthel header... and if you use precompiled headers... you need to include the header after...

So yes it will work.....

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

Post: #11
RE: STRUCTS
I include it after the Esenthel header. And no, it doesn't work your solution, at least for me (VS and Xcode).

IRC: irc.freenode.net
Channel: #Esenthel
05-13-2012 04:19 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #12
RE: STRUCTS
Dunno what you have done in your project but i used the standard EE tutorial project and added a .h file to it... included it after the stdafx.h. I didn't use any ifndef cause you don't really need them if your project has a good structure.

I'm 100% sure that my code compiles and runs but it doesn't matter now.

There is always evil somewhere, you just have to look for it properly.
05-13-2012 04:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
cmontiel Offline
Member

Post: #13
RE: STRUCTS
I am using the MMO example as base project. Maybe there is some issue related to headers.

Anyway, declaring structs names inside the .cpp it works.

IRC: irc.freenode.net
Channel: #Esenthel
05-13-2012 04:47 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #14
RE: STRUCTS
in headers you muse use the "extern" keyword before declaring variables.
Code:
STRUCT (ExClass1, GuiObjs)

    static void someFunction();
}extern Var1;
05-16-2012 11:39 AM
Find all posts by this user Quote this message in a reply
Post Reply