PDA

View Full Version : typedef static const QString Tag;



sunil.thaha
18th January 2006, 12:00
What is wrong with


typedef static const QString Tag;


is there a way around - using the #define

Codepoet
18th January 2006, 13:11
static in typedefs is illegal. You have to specify it at every definiton of a variable / member.

sunil.thaha
19th January 2006, 04:45
static in typedefs is illegal. You have to specify it at every definiton of a variable / member.

Or U can Use
#define Tag static cosnt QString

yop
19th January 2006, 07:52
Or U can Use
#define Tag static cosnt QString
Yes you can but please don't. It will just save you a few key strokes but you get all the evil things of preprocessor usage.

sunil.thaha
19th January 2006, 08:42
Yes you can but please don't. It will just save you a few key strokes but you get all the evil things of preprocessor usage.

Like what. the whole Qt relies on preprocessors isn't ?

yop
19th January 2006, 08:45
Like what. the whole Qt relies on preprocessors isn't ?
I think you'll find this (http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.8) intresting (the whole faq is of great value). And could you give me an example of how Qt relies on the preprocessor.

Codepoet
19th January 2006, 09:20
Qt uses several macros:
Q_OBJECT, signals slots, foreach...
foreach is a very bad one: Just try something like foreach(QPair<int, QString> p, c)... How many parameters has that "call"? 2? Not really...:rolleyes:

yop
19th January 2006, 09:35
Qt uses several macros:
Q_OBJECT, signals slots, foreach...
foreach is a very bad one: Just try something like foreach(QPair<int, QString> p, c)... How many parameters has that "call"? 2? Not really...:rolleyes:
I bet you have used more than one gui APIs. I have a really hard time decrypting compile time errors due to macro expansions using them (but I've never passed the nwebie state in any of them so who knows maybe it's my fault ;)). Qt is the cleaner one when it comes down to that point (probably due to the meta compilation - moc). The most cryptic error I've encoutered is the vtable thingy, after that it's smooth. Maybe I'm just lucky... Do you agree on avoiding macros whenever possible?

Codepoet
19th January 2006, 09:54
Try to avoid macros whereever possible. C++ misses some features so we need the preprocessor sometimes as in Qt.
The best known exception to this rule are the include guards. Those you need, since #pragma once is bad and does not work like expected if you read the gcc docs...


Offtopic:
Say, around 9 years of C++ experience and several other languages. Much work with stl and boost and you learn how to decipher those compiler warnings ;)
It's not exactly right with the GUI APIs: long long ago WinAPI, then nothing (programmed internals without GUI) and since half a year Qt 4 after trying out wxwidgets and deciding that Qt 4 is better :D
If you never encountered those messages which are several pages long you are really lucky - I should send you a sample the next time I hit one ;)

yop
19th January 2006, 10:10
If you never encountered those messages which are several pages long you are really lucky - I should send you a sample the next time I hit one ;)Not lucky, I'm just the ideal API client, I don't mess too much with it, I most probably will only subclass something at one level, I'm not doing much of inheritance, in general I don't consider myself an experienced developer, I'm in the state of the learning process were I'm trying to do everything by the book, (after having written many lines of nasty, ugly, evil code). To get past the rules you must firstly understand the rules I guess and that's why I'm here, share the little I know and above all learn. But it would be fun if I saw something like those messages you say, it's like taking a look at what comes next :)

wysota
20th January 2006, 20:34
Hmm... what do you all want from C preprocessor? Almost all C programs rely on it and it is very helpfull when used properly. Qt heavily uses preprocessing too. All private data in Qt4 relies on preprocessing.

jacek
20th January 2006, 21:19
what do you all want from C preprocessor?
It doesn't check whether argument types are correct, using expressions as parameters isn't safe, it may create vast amounts of weird error messages while the problem is only in one place, and so on.

Of course macros can be useful, iff used in a correct way.

wysota
21st January 2006, 10:05
Of course macros can be useful, iff used in a correct way.

You can say that about almost everything...

yop
21st January 2006, 17:05
I am trying hardly to get rid of them but that is not completely possible. Anyway whenever I find it absolutely necessery to use one I make all of my colleagues read it and warn me about possible problems. I guess I'm too afraid of them :(