as title. The code and the error messages are posted as follows. VC2005 + wtl. I checked some articles and references on polymorphism and operator overload, but haven't figured out the problems. So why it's wrong? How to correct it? Thanks in advance.
Basically the classes are used to query values (can be interpreted to different built-in types e.g. dword, char*, etc.) according to key.
Code: (you can copy it into your VC compiler and try)
-----
#include "stdafx.h" // wtl required
class ObjValue
{
};
class ObjKey
{
public:
class ObjValueProxy {
public:
ObjValue QueryValue() const;
operator ObjValue() const;
};
};
ObjValue ObjKey::ObjValueProxy::QueryValue() const
{
ObjValue* v = new ObjValue;
return *v;
// i don't care the value in this example
// in reality, it's the result of some query action
}
operator ObjKey::ObjValueProxy::ObjValue() const
{
return QueryValue();
}
Errors:
------
Compiling...
testoperatoroverloading.cpp
d:\test\testoperatoroverloading.cpp(25) : error C2039: 'ObjValue' : is not a member of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(10) : see declaration of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(26) : error C2270: '.?AVObjValue@@' : modifiers not allowed on nonmember functions
d:\test\testoperatoroverloading.cpp(26) : error C2801: 'operator ObjValue' must be a non-static member
d:\test\testoperatoroverloading.cpp(27) : error C3861: 'QueryValue': identifier not found
test - 4 error(s), 0 warning(s)
Basically the classes are used to query values (can be interpreted to different built-in types e.g. dword, char*, etc.) according to key.
Code: (you can copy it into your VC compiler and try)
-----
#include "stdafx.h" // wtl required
class ObjValue
{
};
class ObjKey
{
public:
class ObjValueProxy {
public:
ObjValue QueryValue() const;
operator ObjValue() const;
};
};
ObjValue ObjKey::ObjValueProxy::QueryValue() const
{
ObjValue* v = new ObjValue;
return *v;
// i don't care the value in this example
// in reality, it's the result of some query action
}
operator ObjKey::ObjValueProxy::ObjValue() const
{
return QueryValue();
}
Errors:
------
Compiling...
testoperatoroverloading.cpp
d:\test\testoperatoroverloading.cpp(25) : error C2039: 'ObjValue' : is not a member of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(10) : see declaration of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(26) : error C2270: '.?AVObjValue@@' : modifiers not allowed on nonmember functions
d:\test\testoperatoroverloading.cpp(26) : error C2801: 'operator ObjValue' must be a non-static member
d:\test\testoperatoroverloading.cpp(27) : error C3861: 'QueryValue': identifier not found
test - 4 error(s), 0 warning(s)