Problem of overloading operator - templatized

Discussion in 'C Programming' started by kausikd, Aug 6, 2010.

  1. kausikd

    kausikd

    Joined:
    Aug 6, 2010
    Messages:
    1
    The following code is compiled via gcc but not via VC9. What's going wrong here.

    ftor.operator ()(b1); is passing just like ftor.f(b1) but not ftor(b1);

    #include "stdafx.h"
    #include <iostream>
    using namespace std;

    class A {};
    class B :public A {};

    struct functor
    {
    template <class T> bool /*f*/operator ()(T* x) { cout << "Generic function is called" << endl; return true; }
    };

    struct my_functor : public functor {
    using functor::/*f*/operator ();
    bool /*f*/operator ()(A* x) { cout << "Function for A is called" << endl; return true;}
    };

    int main()
    {
    my_functor ftor;
    int a=10;
    double b=100.0;
    B *b1 = new B;
    A *a1 = new A;

    ftor/*.f*/(&a);
    ftor/*.f*/(&b);
    ftor/*.f*/(b1);
    //ftor.operator ()(b1); // This one is passing but not ftor(b1)
    ftor/*.f*/(a1);
    }
    kausikd, Aug 6, 2010
    #1
    1. Advertising

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. Paul Escherton

    Templatized operator () overload

    Paul Escherton, Nov 10, 2003, in forum: C++
    Replies:
    2
    Views:
    367
    tom_usenet
    Nov 10, 2003
  2. mrstephengross
    Replies:
    5
    Views:
    595
    Larry I Smith
    May 18, 2005
  3. StephQ
    Replies:
    1
    Views:
    322
    amparikh@gmail.com
    Mar 11, 2007
  4. josip.krapac@gmail.com

    Problem with compilation of templatized code

    josip.krapac@gmail.com, Jun 27, 2008, in forum: C++
    Replies:
    2
    Views:
    323
    Noah Roberts
    Jun 27, 2008
  5. kcsasquatch
    Replies:
    2
    Views:
    561
    Johannes Schaub (litb)
    Aug 31, 2010
Loading...

Share This Page