By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.