This is a discussion on Checking Object's class. within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by whiteflags It's called the named constructor idiom. As I thought, someone would give a quick answer... In ...
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yes, as is implied by the page I linked. Anyway, it's static methods returning objects of your class.
I still find it a bit confusing, since even though there is no default constructor in the linked example, you can make a stack object. And if you can make a stack object using a (magic) default constructor like that, I don't see how that prevents inheritance.
I wonder if C++0x fixes this because otherwise inheritance in C++ is poorly conceived.
I can't talk about other systems, but making sure you don't have derived objects sure is a song and dance in C++. I just wish there were a keyword or something so it's completely clear what the intentions are of the person writing the class.
Sorry Elysia, you're 100% right, it seems you're experienced in this case.
Yes, it's expensive to do that, otherwise it will be complicated (creating your own programming language or creating sub-preproccessor just like Qt's moc).
I think I'll give up on this and just use only what I needed to solve things.
Thank you very much.
Just GET it OFF out my mind!!
Stroustrup provides another "song and dance" solution that does not have such a limitation in his answer to the FAQ Can I stop people deriving from my class?.Originally Posted by Sebastiani
Personally, unless documented otherwise, I stick to the rule that a class with no virtual functions should not be used as a base class. But yeah, having the rule enforced by a language feature would probably be good.