Hi,
I have a problem with the compilation of some code. It appears when mixing generics with pointers and const.
Here is a dummy sample :
The compilation error is :
main-test.cpp(23) : error C2664: 'has' : cannot convert parameter 1 from 'const class Object *' to 'class Object *const & '
Reason: cannot convert from 'const class Object *' to 'class Object *const '
Conversion loses qualifiers
I can't understand why this error occurs, looking at the source code, it seems valid.
What must I do to avoid the problem?
--
Globos
I have a problem with the compilation of some code. It appears when mixing generics with pointers and const.
Here is a dummy sample :
Code:
class Object//Our dummy data class
{};
template<class G>//A generic class defining a request
class A
{
public:
bool has (const G& v) const
{ return true; }
};
class B//Uses A<> with pointers.
{
public:
bool found (const A<Object*>& a, const Object& v) const
{ return a.has (&v); }
};
int main ()//some test
{
A<Object*> a;
Object obj;
B b;
b.found (a, obj);
return 0;
}
The compilation error is :
main-test.cpp(23) : error C2664: 'has' : cannot convert parameter 1 from 'const class Object *' to 'class Object *const & '
Reason: cannot convert from 'const class Object *' to 'class Object *const '
Conversion loses qualifiers
I can't understand why this error occurs, looking at the source code, it seems valid.
What must I do to avoid the problem?
--
Globos