help on type conversion operator overloading error...

Discussion in 'C Programming' started by 2simple, Oct 19, 2006.

  1. 2simple

    2simple

    Joined:
    Oct 19, 2006
    Messages:
    2
    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)
     
    2simple, Oct 19, 2006
    #1
    1. Advertising

  2. 2simple

    2simple

    Joined:
    Oct 19, 2006
    Messages:
    2
    reason found, the correct form should be:

    ObjKey::ObjValueProxy::eek:perator ObjValue() const

    so please close this thread, thanks.
     
    2simple, Oct 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    2
    Views:
    423
    Ivan Vecerina
    Oct 6, 2004
  2. Philip Pemberton
    Replies:
    5
    Views:
    564
    DaKoadMunky
    Oct 24, 2004
  3. dascandy@gmail.com
    Replies:
    11
    Views:
    735
    James Kanze
    May 16, 2007
  4. hurcan solter
    Replies:
    3
    Views:
    733
    Cholo Lennon
    Aug 29, 2007
  5. Martin T.
    Replies:
    7
    Views:
    820
    Martin T.
    Mar 10, 2008
Loading...

Share This Page