Re: Different classes instantiated from templates SHARE static members!!!
Re: Different classes instantiated from templates SHARE static members!!!
- Subject: Re: Different classes instantiated from templates SHARE static members!!!
- From: David A Rowland <email@hidden>
- Date: Fri, 5 Jan 2007 17:10:23 -0800
Title: Re: Different classes instantiated from templates
SHARE st
At 4:14 PM -0800 1/5/07, David A Rowland wrote:
At 4:48 PM -0700 1/5/07, Scott Ribe
wrote:
Holy Cow! Am I going to have to keep a
machine with CodeWarrior on it for
the next 10 years???
The following outputs "foo2 - foo2" instead of "foo1 -
foo2"!
template< typename T > class t { public: static const char *
foo; };
typedef t< char > c1;
template< typename T > const char * c1::foo =
"foo1";
typedef t< float > c2;
template< typename T > const char * c2::foo =
"foo2";
int main (int argc, char * const argv[]) {
c1 obj1; c2 obj2;
std::cout << obj1.foo << " - "
<< obj2.foo << std::endl << std::flush;
return 0;
}
"foo" is a static member. It
can't be bound to any object of that class. It should not be possible
to write
obj1.foo
After checking the Standard and Stroustrup, I find that it is
quite possible to "bind" a static member to an object in
that way. It's just poor practice, IMO.
When I define the classes as simple, non-template classes, the
output is correct. "foo2 - foo2" is some unhappy consequence
of the template processing.
DAR
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden