Hi,
In the example below, I use 2 "dummy" classes (LoKey and HiKey) to choose between 2 constructors in MyKey class. This works very fine except in the last test-funktion.
Compiling with MS Visual C++ 2019 I get the following compilation error:
error C2664: 'void test(MyKey)': cannot convert argument 1 from 'MyKey (__cdecl *)(LoKey (__cdecl *)(void))' to 'MyKey'.
Compiling and running the program without the line "test(k3)" works fine.
I've tried with several online compilers such as "C++ Shell" and "
https://www.jdoodle.com/online-compiler-c++". They all complain complain the same issue.
So I guess it's not a compiler error, but I just cannot understand why there is a problem.
Can anyone help me on this?
Kind regards
Henrik T.
#include <iostream>
#include <string>
class LoKey {};
class HiKey {};
class MyKey
{
public:
MyKey(LoKey, int i = -1, int j=-1) : i_(i), j_(j) {}
MyKey(HiKey, int i = 100, int j=999) : i_(i), j_(j) {}
int i_,j_;
};
void test(MyKey k)
{
std::cout << "I-Value=" << k.i_ << std::endl;
}
int main()
{
LoKey lokey;
MyKey k1(lokey);
test(k1);
MyKey k2(LoKey(),33);
test(k2);
MyKey k3(LoKey());
//test(k3); /* This line produces compilation error */
}