Advertisement
A couple years ago, a friend of mine who's a fellow C++ geek mentioned that virtual methods should not be invoked from a constructor because it's unknown whether a given C++ implementation initializes a class's virtual table before or after its constructor is invoked.
This isn't an issue with the C++ version I've worked with (Microsoft's Visual Studio C++) but I'm wondering whether anyone here has run into an implementation where it IS an issue. I haven't checked g++ yet...
Best, Don
This isn't an issue with the C++ version I've worked with (Microsoft's Visual Studio C++) but I'm wondering whether anyone here has run into an implementation where it IS an issue. I haven't checked g++ yet...
Best, Don
Advertisement
Advertisement
-
Re: C++ implementations (virtual methods in constructor OK?)
Mon, March 15, 2004 - 2:29 PMYour geek friend was right. Never call virtual functions from a constructor or a destructor. During construction and destruction the vtables are switched (they must be, if you think about it). It's part of the C++ Standard. -
-
Re: C++ implementations (virtual methods in constructor OK?)
Thu, March 18, 2004 - 1:18 PMSuggest a good book that would help me master C++ with this level of knowledge? -
-
Re: C++ implementations (virtual methods in constructor OK?)
Tue, March 23, 2004 - 3:37 PMHave a look at my book "C++ In Action" online at www.relisoft.com/book . If you like it, you can buy one used for less than $10 (there's a link there). -
-
Re: C++ implementations (virtual methods in constructor OK?)
Tue, March 23, 2004 - 3:40 PMVERY cool! Thanks for the tip!
-
-
-
