template non type parameters in operator overloaded function

Discussion in 'C++' started by aravindap, Oct 23, 2008.

  1. aravindap

    aravindap Guest

    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.
     
    aravindap, Oct 23, 2008
    #1
    1. Advertisements

  2. 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.
     
    Gianni Mariani, Oct 23, 2008
    #2
    1. Advertisements

  3. aravindap

    aravindap Guest

    On Oct 24, 12:35 am, Gianni Mariani <> 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 ?
     
    aravindap, Oct 24, 2008
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sebastian Faust
    Replies:
    4
    Views:
    596
    Sebastian Faust
    Oct 18, 2003
  2. CoolPint
    Replies:
    2
    Views:
    485
    Ivan Vecerina
    Nov 8, 2003
  3. Robert Allan Schwartz
    Replies:
    1
    Views:
    534
    Victor Bazarov
    Aug 9, 2004
  4. CoolPint
    Replies:
    3
    Views:
    682
    Victor Bazarov
    Feb 13, 2005
  5. Replies:
    4
    Views:
    682
    Noah Roberts
    Feb 10, 2009
  6. Rennie deGraaf

    Strings as non-type template parameters

    Rennie deGraaf, May 31, 2010, in forum: C++
    Replies:
    11
    Views:
    1,179
    James Kanze
    Jun 3, 2010
  7. , India
    Replies:
    8
    Views:
    590
    James Kanze
    Jul 19, 2010
  8. kito
    Replies:
    2
    Views:
    594
Loading...