wxWidgets and templates Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
kolo
Earned some good credits
Earned some good credits
Posts: 120
Joined: Tue Jun 21, 2005 1:19 pm
Location: Russia, Cheboksary
Contact:

wxWidgets and templates

Post by kolo »

I have the following code

Code: Select all

template<class T>
class MyClass : public T
{
   ...
   DECLARE_DYNAMIC_CLASS(MyClass)
}
...
IMPLEMENT_DYNAMIC_CLASS(/*I don`t know that I must put here*/)
I try

Code: Select all

IMPLEMENT_DYNAMIC_CLASS(MyClass<BaseClass>, BaseClass)
,
but this code is wrong.
Is anybody have an idea how I can solve that problem?

Regards, Kolo.
only MSW & MSVS ))
boxcarmiba
Experienced Solver
Experienced Solver
Posts: 67
Joined: Wed Jun 14, 2006 7:35 am

Post by boxcarmiba »

i know this isn't what you want to hear, but i would refer you to
http://www.wxwidgets.org/develop/standard.htm
that specifically discourages the use of templates in wxWidgets programming. before discovering the standard, i had been using templates, but since following the advice given, i've found things go a lot more smoothly, compile and execute quicker and all in all makes the program a lot more portable.
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

# New or not widely supported C++ features

1. Don't use C++ templates
2. Don't use C++ exceptions
3. Don't use RTTI
4. Don't use namespaces
5. Don't use STL
6. Don't declare variables inside for()
7. Don't use nested classes
Thats a joke or?

First, I use Templates and wxWidgets and it works. Not always perfectly,
but it saves me a lot of time. So, I prefer to have easier programming,
then following those, imho pretty old and mostly stupid advices.
Sure, you shouldn't use DECLARE_DYNAMIC and and other Macros then,
but it mostly works without them. Often you have to understand a bit more
about the background of the wxClasses, and then you can implement templates
for connecting things to gether etc. For Events I mostly use the Connect methods,
so I don't have a problem with macros.

To the rest:
2) Some libraries throw exception, not catching them isn't quite the concept.
Also std::exception is the Standard Exception class in C++.
3) RTTI is sometimes needed, if you want to know things at runtime.
I think even wxDynamicCast needs RTTI...
4) you should really use namespaces if you write a library or anykind of program that is a bit bigger then a calculator.
5) STL is a lot easier and better then the wxWidgets Containers, also boost builds on top of STL. Also STL is C++ Standard.
This simply means: Do not use the Standard, thats a bit more then stupid.
6) Will not really harm your programms.
7) Well, nested classes are sometimes useful when it comes to implementation details. (STL iterators f.e.)
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
Right phlox81, this *should* be a joke, but apparently it isn't... Either that or somebody forgot to update the guidelines in question for a looooong time.

The thing that I suppose to be the real WTF here is
# New or not widely supported C++ features
I mean, come on! Where are we living? 1995??
It must have been ages since I last worked with a compiler that didn't support template, namespaces, exceptions etc...
Ok, to be honest VC4 has some problems with that, but even there most stuff works.

I guess this is quite obsolete now. From what I gathered, the upcoming 3.0 release should use STL where possible. I doubt that it will use exceptions, although that this would be a real addition.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

upCASE wrote:I mean, come on! Where are we living? 1995??

I guess this is quite obsolete now. From what I gathered, the upcoming 3.0 release should use STL where possible. I doubt that it will use exceptions, although that this would be a real addition.
Just a friendly reminder that those are standards that need to be followed when writing code for the wxWidgets project itself, not for your own application. Templates, STL, and whatever else is fine, only I don't think kolo's example usage of templates is possible.

Those standards were set for the wxWidgets 2 library (everything from way back with 2.0, 2.2, 2.4, 2.6, and the 2.8 version due out soon). While most compilers wxWidgets is used with support STL and templates, some still have buggy implementations, or small differences here and there. Despite where current modern day compilers are at as far as that goes, if wxWidgets supported some old Watcom compiler for 2.0 (see the Supported Platforms page), it should keep support for it throughout the v2 lifecycle. This is why these standards are being discussed for v3 (wxTNG).

Simply deciding to go ahead and use them with v2 could break compatibility in places you never thought about, destabilize the branch, and potentially introduce all kinds of new bugs.
User avatar
kolo
Earned some good credits
Earned some good credits
Posts: 120
Joined: Tue Jun 21, 2005 1:19 pm
Location: Russia, Cheboksary
Contact:

Post by kolo »

I solve this problem by parsibg macroses.
only MSW & MSVS ))
Jamie
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Post by Jamie »

Post Reply