473,385 Members | 2,004 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,385 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 2710
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...

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.