-
October 21st, 2013, 01:28 PM
#18
Re: Where does a template function get instantiated ?
Originally Posted by John E
Is it considered bad practice (or at least very risky) for a template class to have static data members?
When you have multi-module projects, it is risky, template class or concrete class, to have static data members. This is the case especially if you rely on the static data being initialized at the point where you're accessing the static data.
The rules of C++ for when static data members are guaranteed to be initialized get complex (at least to me they are). If you have the entire program in a single module, static initialization becomes easy. It's when you're dealing with multi-module programs where it becomes risky.
Here is a link to such a scenario:
http://www.parashift.com/c++-faq/static-init-order.html
I have also seen static members declared in other modules to not be initialized after main() is called.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 21st, 2013 at 01:31 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|