Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template non type parameters in operator overloaded function

Reply
Thread Tools

template non type parameters in operator overloaded function

 
 
aravindap
Guest
Posts: n/a
 
      10-23-2008
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: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.
 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      10-23-2008
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.
 
Reply With Quote
 
 
 
 
aravindap
Guest
Posts: n/a
 
      10-24-2008
On Oct 24, 12:35*am, Gianni Mariani <(E-Mail Removed)> wrote:
> aravindapwrote:
>
> ...
>
> > 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.


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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in calling an overloaded operator= from inside anotheroverloaded operator Afshin C++ 0 08-12-2011 12:01 PM
deducing the argument type of overloaded function call operator subramanian100in@yahoo.com, India C++ 8 07-19-2010 05:24 PM
Non-type function template parameters mmomike@gmail.com C++ 4 02-10-2009 06:16 PM
"overloaded cast operator" and "operator const" John Goche C++ 2 09-04-2006 02:48 PM
Help Required: Operator overloaded function template and Friend CoolPint C++ 3 02-13-2005 04:49 PM



Advertisments