template non type parameters in operator overloaded function

A

aravindap

Hi All,
I am trying to do following things,

#include <iostream>

using namespace std;
class x{

------- // member variables

public:

template <int flag>
void setFlag ();

template <int id>
void operator+= (x& obj1);
}

template <int flag>
void x::setFlag(){ cout << " inside setFlag " << flag << endl; }

template <int id>
void x::eek:perator+=(x& obj1){ cout << "inside +=" << id << endl; }

int main()
{
x o1, o2;
o1.setFlag <1> ();
o1 += <22>o2 ; /* Line no 3 */
o1.operator+= <22> (o2); /* Line no 4 */
}

Problem
========
In line no 3 I am getting " error: expected primary-expression before
'<' token"
If i modify line 3 as line no 4, no issues. I am getting proper
output.
Please let me know how my implementation should be to have something
similar to line 3 , I dont want to have like one in line no 4.

Thanks and Regards,
Aravind.
 
G

Gianni Mariani

aravindap wrote:
....
Please let me know how my implementation should be to have something
similar to line 3 , I dont want to have like one in line no 4.

I think you're out of luck. I don't think C++ supports the line 3 syntax.
 
A

aravindap

aravindapwrote:

...


I think you're out of luck. I don't think C++ supports the line 3 syntax.

Thanks Gianni, for now I will settle for line no 4 syntax, is it
possible for us to suggest people to include such syntax ?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top