473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

static member initialization

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>::pType T<C>::D<A>::Val = A;

int main()
{
}

But if one replaces line#13 with

template<typename T<C>::pType A>

it does not.
Does anybody know why?

Oct 8 '06 #1
3 2712
ki******@gmail.com 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>::pType T<C>::D<A>::Val = A;

int main()
{
}

But if one replaces line#13 with

template<typename T<C>::pType 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
Oct 8 '06 #2
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>::pType) == typeid(typename C::Type*)) returns
true. Moreover struct D parametrized using pType not C::Type*.

Oct 9 '06 #3
ki******@gmail.com 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>::pType) == 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>::pType' the T<Chasn'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
Oct 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: cppaddict | last post by:
I have class with two static member objects, one of type int and one of type vector<int>. static int myStaticMemberInt static vector<int> myStaticMemberVector; I know how to initialize the...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
3
by: Tran Tuan Anh | last post by:
Dear all, I am new with C++ and very confused with some features. Really appreciate if you can explain to me some of stuffs below. I define a class: class A { static A* instance = 0; };
3
by: Mike - EMAIL IGNORED | last post by:
MyClass { //I have a static member method: void static myMethod(); //and a static data member: static MyType myData; }; //In the .cpp file: void MyClass::myMethod()
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
7
by: Spoon | last post by:
Hello everyone, I have a Packet class I use to send packets over the Internet. All the packets sent in a session are supposed to share a common random ID. I figured I'd use a static const...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
5
by: desktop | last post by:
Why is this struct illegal: #include<iostream> struct debug { std::string d1 = "bob\n"; }; I get this error:
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
2
by: Ranganath | last post by:
Hi, Why is there a restriction that only integral types can be made static constant members of a class? For e.g., class B { private: static const double K = 10; };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.