Problem of overloading operator - templatized

Joined
Aug 6, 2010
Messages
1
Reaction score
0
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);
}
 

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

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top