472,783 Members | 953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 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 1359
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.