473,396 Members | 2,011 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.

How to hide the "<>" token when the template class already has adefault "typename".

Ed
Hi, guys,
Here is a simple template class definition:

template <typename T = int>
class Point {
public:
T X;
T Y;
T Z;
};

int main()
{
Point<point1;
Point<doublepoint2;
}
There is already a default type "int" for class Point. But I still
need to type "<>" when creating a object.
I don't want to put "<>" in the code, because I think it's useless.
Point<point1;
How can I write the code like this
Point point1;

I tried "typedef", but it doesn't work.
typedef Point<Point;

Thanks,
Ed.
Aug 5 '08 #1
4 1402
On Aug 5, 5:22 am, Ed <seah...@gmail.comwrote:
Hi, guys,
Here is a simple template class definition:

template <typename T = int>
class Point {
public:
T X;
T Y;
T Z;

};

int main()
{
Point<point1;
Point<doublepoint2;

}

There is already a default type "int" for class Point. But I still
need to type "<>" when creating a object.
I don't want to put "<>" in the code, because I think it's useless.
Point<point1;
How can I write the code like this
Point point1;

I tried "typedef", but it doesn't work.
typedef Point<Point;
try

int main()
{
typedef Point<NPoint;
NPoint point_n;
}
Aug 5 '08 #2
On 2008-08-05 05:22:07 -0400, Ed <se*****@gmail.comsaid:
>
I tried "typedef", but it doesn't work.
typedef Point<Point;
Use a different name. You can't use the same name for a template and a class.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 5 '08 #3
Ed
On Aug 5, 6:43 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2008-08-05 05:22:07 -0400, Ed <seah...@gmail.comsaid:
I tried "typedef", but it doesn't work.
typedef Point<Point;

Use a different name. You can't use the same name for a template and a class.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
But "<>" seems unnecessary.
Aug 5 '08 #4
Ed wrote:
On Aug 5, 6:43 pm, Pete Becker <p...@versatilecoding.comwrote:
>On 2008-08-05 05:22:07 -0400, Ed <seah...@gmail.comsaid:
>>I tried "typedef", but it doesn't work.
typedef Point<Point;

Use a different name. You can't use the same name for a template
and a class.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

But "<>" seems unnecessary.
It is just as necessary as the "()" in a function call:

p = f;
i = f();

have totally different meanings.

That's the way the language is designed.
Bo Persson
Aug 5 '08 #5

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

Similar topics

3
by: janzon | last post by:
Hi! Sorry for the bad subject line... Here's what I mean. Suppose we deal with C++ standard integers lists (the type is indifferent). We have a function f, declared as list<intf(int); Now...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.