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

E

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<double> point2;
}


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.
 
S

Salt_Peter

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<double> point2;

}

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;
}
 
B

Bo Persson

Ed said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top