oplaTech About Teaching Archive
Oplatek's external memory

C++ suprising execution order


#include

using std::cout;
using std::endl;

template void func(X val) {
cout << "func" << endl;
}

// partial specialisation
template void func(double val) {
cout << "func" << endl;
}

void func2(double x) {
cout << "func2" << endl;
}

class obj {
public:
void callFunc() {
func(4.5);
func2(6.3);
}
private:
// even conversion here, but still callled!
void func(int val) {
cout << "obj::func" << endl;
}

// even conversion here, but still callled!
void func2(int val) {
cout << "obj::func2" << endl;
}
};

int main() {
obj o;
o.callFunc();
}


OUTPUT:

obj::func
obj::func2