T
twisteddweeb
Trying to learn the basics & this one has me stumped. Goggle hasn't
been too much help either.
How can I change the following so that it's the subclass's () operator
that gets called rather than the base class's () operator?
====================================================
#include <iostream>
#include <map>
using namespace std;
class BaseClass {
public:
void operator () (void) {
cout << "I don't want this to print\n";
}
};
class SubClass : public BaseClass {
public:
void operator () (void) {
cout << "I want this to print\n:";
}
};
int main(int argc, char** argv) {
map<int, BaseClass> table;
map<int, BaseClass>::iterator pos;
SubClass action;
//table.insert(pair<int, BaseClass>(1, action));
table.insert(pair<int, SubClass>(1, action));
pos = table.find(1);
pos->second();
return 0;
}
==================================================
Program output...
$ make && ./test
g++ -Wall -o test test.cc
I don't want this to print
==================================================
Yes, I've tried virtual functions... I've tried everything that
doesn't work
If this is a FAQ, I apologize.
thanks
dweeb
been too much help either.
How can I change the following so that it's the subclass's () operator
that gets called rather than the base class's () operator?
====================================================
#include <iostream>
#include <map>
using namespace std;
class BaseClass {
public:
void operator () (void) {
cout << "I don't want this to print\n";
}
};
class SubClass : public BaseClass {
public:
void operator () (void) {
cout << "I want this to print\n:";
}
};
int main(int argc, char** argv) {
map<int, BaseClass> table;
map<int, BaseClass>::iterator pos;
SubClass action;
//table.insert(pair<int, BaseClass>(1, action));
table.insert(pair<int, SubClass>(1, action));
pos = table.find(1);
pos->second();
return 0;
}
==================================================
Program output...
$ make && ./test
g++ -Wall -o test test.cc
I don't want this to print
==================================================
Yes, I've tried virtual functions... I've tried everything that
doesn't work
If this is a FAQ, I apologize.
thanks
dweeb