N
Narinder
Hello,
Can't someone explain what should be the correct behaviour of the
following code:
__________________________________
#include<iostream>
using namespace std;
struct klass
{
template<class T>
operator T&()
{
throw("I am NON-const version");
}
template<class T>
operator const T&()
{
throw("I am CONST version");
}
};
int main()
{
try
{
klass k;
double x = k;
}
catch(const char *err)
{
cout << err << endl;
}
}
__________________________________
Compiled with MSVC 2010, language extensions disabled I get the
output: "I am CONST version"
Compiled with gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) with
command line 'g++ -pedantic -ansi' I get the output :"I am NON-const
version"
Thanks in advance.
N
Can't someone explain what should be the correct behaviour of the
following code:
__________________________________
#include<iostream>
using namespace std;
struct klass
{
template<class T>
operator T&()
{
throw("I am NON-const version");
}
template<class T>
operator const T&()
{
throw("I am CONST version");
}
};
int main()
{
try
{
klass k;
double x = k;
}
catch(const char *err)
{
cout << err << endl;
}
}
__________________________________
Compiled with MSVC 2010, language extensions disabled I get the
output: "I am CONST version"
Compiled with gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) with
command line 'g++ -pedantic -ansi' I get the output :"I am NON-const
version"
Thanks in advance.
N