Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static member initialization

Reply
Thread Tools

static member initialization

 
 
kiryazev@gmail.com
Guest
Posts: n/a
 
      10-08-2006
Hello! The following code compiles fine.

template <typename C>
struct T
{
typedef typename C::Type * pType;
template <pType A>
struct D
{
static const pType Val;
};
};

template<typename C>
template<typename C::Type* A> // line #13
const typename T<C>:Type T<C>:<A>::Val = A;

int main()
{
}

But if one replaces line#13 with

template<typename T<C>:Type A>

it does not.
Does anybody know why?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-08-2006
wrote:
> Hello! The following code compiles fine.
>
> template <typename C>
> struct T
> {
> typedef typename C::Type * pType;
> template <pType A>
> struct D
> {
> static const pType Val;
> };
> };
>
> template<typename C>
> template<typename C::Type* A> // line #13
> const typename T<C>:Type T<C>:<A>::Val = A;
>
> int main()
> {
> }
>
> But if one replaces line#13 with
>
> template<typename T<C>:Type A>
>
> it does not.
> Does anybody know why?


I can tell you the Comeau online trial compiler says it's
because "declaration is incompatible with constant
"C::Type *A" (declared at line 5)"

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
kiryazev@gmail.com
Guest
Posts: n/a
 
      10-09-2006
Victor Bazarov wrote:

> I can tell you the Comeau online trial compiler says it's
> because "declaration is incompatible with constant
> "C::Type *A" (declared at line 5)"


Thanks. But I don't see the difference between these two variants.
(typeid(typename T<C>:Type) == typeid(typename C::Type*)) returns
true. Moreover struct D parametrized using pType not C::Type*.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      10-09-2006
wrote:
> Victor Bazarov wrote:
>
>> I can tell you the Comeau online trial compiler says it's
>> because "declaration is incompatible with constant
>> "C::Type *A" (declared at line 5)"

>
> Thanks. But I don't see the difference between these two variants.
> (typeid(typename T<C>:Type) == typeid(typename C::Type*)) returns
> true. Moreover struct D parametrized using pType not C::Type*.


I was curious about that as well. I don't have the exact answer, for
you though. My best guess is that by the time you try using the
'T<C>:Type' the T<C> hasn't been instantitated yet. It would cause
an instantiation but does not until you actually instantiate the 'Val'
member in 'D', and then the compiler probably gets lost trying to
resolve what 'pType' is supposed to be. The difference with the 'Val'
declaration itself is that here you're trying to use it as a template
argument.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
initialization of array as a member using the initialization list aaragon C++ 2 11-02-2008 04:57 PM
error C2614: 'CYYYRegister' : illegal member initialization:'CRequest' is not a base or member Angus C++ 1 03-06-2008 11:38 AM
Can a static member function access non-static member? dolphin C++ 3 12-05-2007 12:39 PM
How to initialize an array member in the member initialization list? jut_bit_zx@eyou.com C++ 3 10-10-2005 12:10 AM
Static class member initialization question Michael Klatt C++ 6 11-18-2003 08:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57