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: Steve Checkoway <email@hidden>
- Date: Fri, 5 Jan 2007 17:05:04 -0800
On Jan 5, 2007, at 3:48 PM, Scott Ribe wrote:
typedef t< char > c1;
template< typename T > const char * c1::foo = "foo1";
This looks wrong. I think gcc accepting this is the bug.
[dualg5:~/temp] steve$ cat b.cc
#include <cstdio>
template <typename T>
struct t { static const char *foo; };
typedef t<char> c1;
template<> const char *c1::foo = "foo1";
typedef t<float> c2;
template<> const char *c2::foo = "foo2";
int main()
{
puts( c1::foo );
puts( c2::foo );
return 0;
}
[dualg5:~/temp] steve$ g++ -Wall -Wmost b.cc
[dualg5:~/temp] steve$ ./a.out
foo1
foo2
In addition, replacing c1::foo with c1().foo and c2::foo with c2
().foo works as expected.
On Jan 5, 2007, at 4:14 PM, David A Rowland wrote:
"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
I don't think that's true. It should use the static type of obj1
(just as it did with my c1() above) to determine which foo to use.
You won't get dynamic look up though.
[dualg5:~] steve$ cat c.cc
#include <cstdio>
struct base { static const char *foo; };
struct derived : public base { static const char *foo; };
const char *base::foo = "base";
const char *derived::foo = "derived";
int main()
{
base b1;
const base &b2 = derived();
derived d;
puts( b1.foo );
puts( b2.foo );
puts( d.foo );
return 0;
}
[dualg5:~] steve$ g++ -Wall -Wmost c.cc
[dualg5:~] steve$ ./a.out
base
base
derived
--
Steve Checkoway
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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