473,385 Members | 1,764 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.

why List<ColorPtr> error2; is not corrent?

hi all,

Local classes and enumerations (in other words, types declared in a
function definition) cannot be involved in template type arguments.

Types that involve unnamed class types or unnamed enumeration types
cannot be template type arguments (unnamed classes or enumerations that
are given a name through a typedef declaration are OK).

An example illustrates these two exceptions:

template <typename T> class List {
...
};

typedef struct {
double x, y, z;
} Point;

typedef enum { red, green, blue } *ColorPtr;

int main()
{
struct Association
{
int* p;
int* q;
};
List<Assocation*> error1; // ERROR: local type in template
argument
List<ColorPtr> error2; // ERROR: unnamed type in template
// argument
List<Point> ok; // OK: unnamed class type named through
// a typedef
}
i think ColorPrt is the name for the unamed type enum { red, green,
blue} * through typedef declaration.

Jul 23 '05 #1
3 1300
baumann@pan wrote:
Local classes and enumerations (in other words, types declared in a
function definition) cannot be involved in template type arguments.
Yes, they have no linkage.
Types that involve unnamed class types or unnamed enumeration types
cannot be template type arguments (unnamed classes or enumerations that
are given a name through a typedef declaration are OK).
Yes, since they have linkage (usually external) and have name if you use
a typedef.
An example illustrates these two exceptions:

template <typename T> class List {
...
};

typedef struct {
double x, y, z;
} Point;

typedef enum { red, green, blue } *ColorPtr;

int main()
{
List<ColorPtr> error2; // ERROR: unnamed type in template
// argument
}
i think ColorPrt is the name for the unamed type enum { red, green,
blue} * through typedef declaration.


ColorPtr is a _pointer_ to an unnamed type. The type a value of ColorPtr
points to is still *unnamed*. 14.3.1 prohibits the use of unnamed types
_and_ the types compound from them.

V
Jul 23 '05 #2

Victor Bazarov wrote:
baumann@pan wrote:
Local classes and enumerations (in other words, types declared in a
function definition) cannot be involved in template type arguments.
Yes, they have no linkage.
Types that involve unnamed class types or unnamed enumeration types
cannot be template type arguments (unnamed classes or enumerations that are given a name through a typedef declaration are OK).


Yes, since they have linkage (usually external) and have name if you

use a typedef.
An example illustrates these two exceptions:

template <typename T> class List {
...
};

typedef struct {
double x, y, z;
} Point;

typedef enum { red, green, blue } *ColorPtr;

int main()
{
List<ColorPtr> error2; // ERROR: unnamed type in template
// argument
}
i think ColorPrt is the name for the unamed type enum { red, green,
blue} * through typedef declaration.
ColorPtr is a _pointer_ to an unnamed type. The type a value of

ColorPtr points to is still *unnamed*. 14.3.1 prohibits the use of unnamed types _and_ the types compound from them.

V


if i write the codes as below
typedef enum { red, green, blue } Color;
typedef Color* ColorPtr;
List<ColorPtr> error2;

i think it will work, is not it?

Jul 23 '05 #3
baumann@pan wrote:
[..]
if i write the codes as below
typedef enum { red, green, blue } Color;
typedef Color* ColorPtr;
List<ColorPtr> error2;

i think it will work, is not it?


It should. And I just confirmed it with Comeau online.

V
Jul 23 '05 #4

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

Similar topics

2
by: Thomas Schulz | last post by:
Hello, I'm using the logging package from python 2.3 on RH linux. Everything in the test program below works fine if we just use the log configuration with 'logging.basicConfig'. For the...
7
by: rahul8143 | last post by:
hello, Is it possible to write a math library function sqrt in C without arithmatic operators(*,+)? can anyone give me hints to do that? regards, rahul
3
by: Crouchie1998 | last post by:
On the following page is for Symantec Antivirus updates: http://www.sarc.com/avcenter/download/pages/US-SAVCE.html Todays virus definition filename & path is: ...
1
by: Chad | last post by:
I'd like to define a set of enums that must be a subset of other enums. Something like this: Public Enum AllErrorNumbers As Integer Error1 = 1 Error2 = 2 Error3 = 3 End Enum Public Enum...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
1
by: vauneen | last post by:
Hi, I'm trying to find a work-around for a javascript issue i have. i have a list of text input fields (created using asp) and onblur, i loop through all fields evaluating each one, making sure it...
1
by: Jake Barnes | last post by:
I've been doing this to get a reference to the body node of a document, but I'm sure there must be something simpler than this: var arrayOfBodyElements = document.getElementsByTagName("body");...
3
by: Patrick C | last post by:
hey everyone, i'm working with a list that would be something like xx = and i want to do some calcuations with each item, lets say subtract one item from the item prior...not bad say...
2
by: Karl Forshee | last post by:
I have a section of code that I'm stumped on how to handle. The Selected options on the drop down menues are not being picked up on the second PHP page. That is to say the variables error, error1 &...
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:
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.