Very weird! wxGetApp redeclaration problem

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Ilici
In need of some credit
In need of some credit
Posts: 4
Joined: Thu May 12, 2005 10:00 am

Very weird! wxGetApp redeclaration problem

Post by Ilici » Thu May 12, 2005 10:11 am

Ok I've been pulling my hair out for two days now with this problem. I'm using Visual Studio .NET. I've created the project by copying the "internat" sample and changing the names like in the tutorial. I've then added my own file which looks like this:

Code: Select all

#include "wx/wxprec.h"

class CloudiaApp : public wxApp
{
public:
	virtual bool OnInit();
};

IMPLEMENT_APP(CloudiaApp)

bool CloudiaApp::OnInit()
{
	return true;
}
That does not compile! It gives the errors:
1: "error C2371: 'wxGetApp' : redefinition; different basic types"
2: "error C2556: 'CloudiaApp &wxGetApp(void)' : overloaded function differs only by return type from 'MyApp &wxGetApp(void)'"

If i comment out "IMPLEMENT_APP(CloudiaApp)" it compiles!! It runs but I get a wx assert saying that my app is not implemented and I should use IMPLEMENT_APP.

I'm using wxWindows 2.4.2, compiled the static libraries, everything went ok.[/code]

vdell
Moderator
Moderator
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Re: Very weird! wxGetApp redeclaration problem

Post by vdell » Thu May 12, 2005 10:42 am

Ilici wrote:

Code: Select all

#include "wx/wxprec.h"

class CloudiaApp : public wxApp
{
public:
    virtual bool OnInit();
};

IMPLEMENT_APP(CloudiaApp)

bool CloudiaApp::OnInit()
{
    return true;
}
Is your class declaration in a separate file? Since you should have

Code: Select all

#ifndef ClaudiaApp_HPP
#define ClaudiaApp_HPP

class CloudiaApp : public wxApp
{
public:
    virtual bool OnInit();
};

DECLARE_APP (CloudiaApp)

#endif

in your header file and

Code: Select all


IMPLEMENT_APP (ClaudiaApp)

in your cpp file.

Btw, if you are just starting your project, do not use wxWidgets 2.4.2, since the latest stable release is 2.6.0!

HTH.
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere

Ilici
In need of some credit
In need of some credit
Posts: 4
Joined: Thu May 12, 2005 10:00 am

Re: Very weird! wxGetApp redeclaration problem

Post by Ilici » Thu May 12, 2005 10:53 am

vdell wrote:
Ilici wrote:
Is your class declaration in a separate file? Since you should have

Code: Select all

#ifndef ClaudiaApp_HPP
#define ClaudiaApp_HPP

class CloudiaApp : public wxApp
{
public:
    virtual bool OnInit();
};

DECLARE_APP (CloudiaApp)

#endif

in your header file and

Code: Select all


IMPLEMENT_APP (ClaudiaApp)

I've tried that too, same result.
in your cpp file.

Btw, if you are just starting your project, do not use wxWidgets 2.4.2, since the latest stable release is 2.6.0!

HTH.
I'll stick to 2.4.2 for now since I'm too lazy to compile the new one on linux (no debian packages available afaik).

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Thu May 12, 2005 10:57 am

Take the minimal sample, and see how it is done there. Simply replace it with your ClaudiaApp and see if it compiles, then tear away the stuff you don't need. ;-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Ilici
In need of some credit
In need of some credit
Posts: 4
Joined: Thu May 12, 2005 10:00 am

Post by Ilici » Thu May 12, 2005 11:15 am

The samples compile ok. I've found another thing: if I rename my class: MyApp, it says that i'm redefining the class! It must have been declared somewhere else somehow ..

Another thing I've found is that removing #include <wx/wxprec.h> and simply using <wx/app.h> will work. However when including other headers it breaks again.

Ilici
In need of some credit
In need of some credit
Posts: 4
Joined: Thu May 12, 2005 10:00 am

Post by Ilici » Thu May 12, 2005 11:27 am

Oh god, sometimes I amaze myself how much I can screw up! I had a "wx" subdirectory in my project directory. It had some stuff created with VisualWx which created ... "app.h" which defined "class myapp" and called the implement macro.

Please excuse me while I punch myself into unconsciousnous :D

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Thu May 12, 2005 11:55 am

That's ok I am glad you found it!

Please do not punch too hard we might need your expertise later on ;-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply