Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

Dean Seo

@Dean Seo
About
Posts
26
Topics
7
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • MFC's message map, no need of &?
    D Dean Seo

    First of all, Thanks you so much for answering my question. However, I think that case that you mentioned is about just "pointer to function."

    Peter_in_2780 wrote:

    the & has always been optional.

    But when using "pointer to MEMBER function", the & is not optional, but necessary as you see below.

    class Test;
    typedef void (Test::*fpop)();
    class Test
    {
    public:
    void Op1(){}
    };

    int main(){
    fpop pFunc;
    pFunc = Test::Op1; // compile error!
    //pFunc = &Test::Op1; // the & is essential.
    return 0;
    }

    I know that MFC's message pump consists of Pointer to member function, which needs the &. Could you explain why? Thanks.

    C / C++ / MFC c++ tutorial question

  • MFC's message map, no need of &?
    D Dean Seo

    It's syntax that we have to put '&' right before pointer to member function. For example here.

    class Test;
    typedef void (Test::*fpop)();
    class Test
    {
    public:
    void Op1(){}
    };

    int main(){
    fpop pFunc;
    pFunc = &Test::Op1; // we must need &

    return 0;
    

    }

    However, when I take a look at ON_COMMAND(or any other messages) in MFC, it seems a bit different from what I think is right. VS6.0 is okay. It follows the right syntax as you see below. You can clearly see & before memberFxn.

    #define ON_COMMAND(id, memberFxn) \
    { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSig_vv, (AFX_PMSG)&memberFxn },
    // ON_COMMAND(id, OnFoo) is the same as
    // ON_CONTROL(0, id, OnFoo) or ON_BN_CLICKED(0, id, OnFoo)

    But in VS2008, it goes a bit weird. There is no & before memberFxn.

    #define ON_COMMAND(id, memberFxn) \
    { WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSigCmd_v, \
    static_cast (memberFxn) },
    // ON_COMMAND(id, OnBar) is the same as
    // ON_CONTROL(0, id, OnBar) or ON_BN_CLICKED(0, id, OnBar)

    Moreover, in spite of the fact that there is no & before memberFxn, each line below works perfectly. 1. ON_COMMAND(ID_APP_ABOUT, CSingleApp::OnAppAbout) // & 2. ON_COMMAND(ID_APP_ABOUT, &CSingleApp::OnAppAbout) // no & I tried to find why, and I was curious if it could be because of static_cast<> but it turned out that static_cast has nothing to do with it. So I am wondering why in VS2008 I have 2 choices where I put & or I don't have to put &.

    C / C++ / MFC c++ tutorial question

  • Ambiguity of 'this' and 'member function' [modified]
    D Dean Seo

    Thank you!

    C / C++ / MFC question c++ help learning

  • Ambiguity of 'this' and 'member function' [modified]
    D Dean Seo

    Thank you so much!! I truly appreciate it!

    C / C++ / MFC question c++ help learning

  • Ambiguity of 'this' and 'member function' [modified]
    D Dean Seo

    Hi,

    xrg_soft@163.com wrote:

    Which complier do you use?

    I use Visual Studio 2008.

    xrg_soft@163.com wrote:

    To make the multiple inheritance follows the standard c++ well, you should using virtual inheritance

    I know that the multiple inheritance needs virtual inheritance. However, when I don't on purpose, the result seems not understandable. Could you explain to me why those 'this' addresses look unrestrained?

    C / C++ / MFC question c++ help learning

  • Ambiguity of 'this' and 'member function' [modified]
    D Dean Seo

    This code below occurs no error but the result seems a bit weird.

    class KBase
    {
    public:
    void BaseFun()
    {
    printf( "KBase::BaseFun() this=%p\n", this );
    }
    };

    class KMiddle : public KBase
    {
    };

    class KMiddle2 : public KBase
    {
    };

    class KDerived : public KMiddle, public KMiddle2
    {
    };

    int main()
    {
    KDerived d;

    d.KBase::BaseFun();   // 0012FF63
    d.KMiddle::BaseFun();  // 0012FF63
    d.KMiddle2::BaseFun();  // 0012FF64 ??
    
    return 0;
    

    }//main()

    BaseFun simply shows this pointer and the result goes.. --------------------------- KBase::BaseFun() this=0012FF63 KBase::BaseFun() this=0012FF63 KBase::BaseFun() this=0012FF64 --------------------------- So my question is why KBase::BaseFun() and KMiddle::BaseFun() show the same address and the only KMiddle2::BaseFun() does the different address? I was looking for the answer by reading Stephen Prata's book and Effective C++ but I couldn't. Thanks in advance.

    modified on Wednesday, August 24, 2011 9:51 PM

    C / C++ / MFC question c++ help learning

  • Pointer to member function in struct
    D Dean Seo

    Hi, I just figured it out myself. But your reply helped me a lot to figure out to make it work! Thank you so much.

    C / C++ / MFC help question

  • Pointer to member function in struct
    D Dean Seo

    Thanks.

    Eugen Podsypalnikov wrote:

    typedef void (*LPSTATEPROC) (void);

    You meant this, right?

    typedef void (CAccount::*LPSTATEPROC) (void);

    But it seems like it doesn't still work and the error occurs at the same line.

    #include
    #include

    #define KEY_ESC 27

    using std::cout;
    using std::endl;

    class CAccount;

    typedef void (CAccount::*LPSTATEPROC) (void);

    struct StateMap
    {
    int input;
    LPSTATEPROC mfp;
    };
    class CAccount
    {
    public:
    enum
    {
    STATE_IDLE,
    STATE_INPUT,
    STATE_WAIT_ACK
    };

    public:
    StateMap map[3];
    int m_iState;

    CAccount();
    
    void OnIdle();
    void OnInput();
    void OnWaitAck();
    

    };//class CAccount

    CAccount::CAccount(){
    map[0].input = 1;
    map[0].mfp = &CAccount::OnIdle;

    map\[1\].input = 2;
    map\[1\].mfp = &CAccount::OnInput;
    
    map\[2\].input = 3;
    map\[2\].mfp = &CAccount::OnWaitAck;
    
    m\_iState = STATE\_IDLE;
    

    }

    void CAccount::OnIdle()
    {
    cout << "OnIdle()" << endl;
    }

    void CAccount::OnInput()
    {
    cout << "OnInput()" << endl;
    }

    void CAccount::OnWaitAck()
    {
    cout << "OnWaitAck()" << endl;
    }

    int main()
    {
    int ch = 0;
    int i;
    CAccount account;

    while ( ch != KEY\_ESC )
    {
    	ch = \_getch();
    	i  = 0;
    	while ( account.map\[i\].input != 0 )
    	{
    		if ( ch == account.map\[i\].input )
    		{
    			(account.(map\[i\].\*mfp))(); // compile error
    		}//if
    		i++;
    	}//while
    }//while
    
    return 0;
    

    }//main()

    How can I change that error line to make it work? Thanks!

    C / C++ / MFC help question

  • Pointer to member function in struct
    D Dean Seo

    Hi, Since I knew The Code Project, it has been helpful a lot. Now I think I have a small misunderstanding about pointer to member function in a struct and I need your help, which will be priceless to me. I am simply trying to see how pointer to member function works and it seems a little tricky. The code I am having a problem with is below.

    #include #include #define KEY_ESC 27

    using std::cout;
    using std::endl;

    class CAccount;

    struct StateMap
    {
    int input;
    void (CAccount::*mfp)();
    };

    class CAccount
    {
    public:
    enum
    {
    STATE_IDLE,
    STATE_INPUT,
    STATE_WAIT_ACK
    };

    public:
    StateMap map[3];
    int m_iState;

    CAccount();
    
    void OnIdle();
    void OnInput();
    void OnWaitAck();
    

    };//class CAccount

    CAccount::CAccount(){
    map[0].input = 1;
    map[0].mfp = &CAccount::OnIdle;

    map\[1\].input = 2;
    map\[1\].mfp = &CAccount::OnInput;
    
    map\[2\].input = 3;
    map\[2\].mfp = &CAccount::OnWaitAck;
    
    m\_iState = STATE\_IDLE;
    

    }

    void CAccount::OnIdle()
    {
    cout << "OnIdle()" << endl;
    }

    void CAccount::OnInput()
    {
    cout << "OnInput()" << endl;
    }

    void CAccount::OnWaitAck()
    {
    cout << "OnWaitAck()" << endl;
    }

    int main()
    {
    int ch = 0;
    int i;
    CAccount account;

    while ( ch != KEY\_ESC )
    {
    	ch = \_getch();
    	i  = 0;
    	while ( account.map\[i\].input != 0 )
    	{
    		if ( ch == account.map\[i\].input )
    		{
    			(account.(map\[i\].\*mfp))(); // compile error
    		}//if
    		i++;
    	}//while
    }//while
    
    return 0;
    

    }//main()

    I just don't know the right syntax for that part. How should I change that error line to make it work? Thanks in advance.

    C / C++ / MFC help question

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Thanks!!!!

    C / C++ / MFC oop question c++ help tutorial

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Thank you!

    C / C++ / MFC oop question c++ help tutorial

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Thanks. I will.

    C / C++ / MFC oop question c++ help tutorial

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Thanks!!!

    C / C++ / MFC oop question c++ help tutorial

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Thank you!

    C / C++ / MFC oop question c++ help tutorial

  • virtual inheritance and polymorphism! [modified]
    D Dean Seo

    Since I found this site, it has helped me improve my skills a lot. I used to ask about MFC but now I need to know the relevancy between virtual inheritance and polymorphism. I tried to find it in Google, but I couldn't find what I'd like to know. Maybe I think it's because virtual inheritence is only used for multiple inheritance, which is considered bad to use. For example, it seems like there is no way to keep polymorphism the way I think it has to be in multiple and virtual inheritance, as you see below.

    class A{};
    class B : public A{};
    class C : public A{};
    class D : public B, public C{};
    int _tmain(int argc, _TCHAR* argv[])
    {
    A* a = new D(); // compile error!
    }

    This seems like a very reasonable compile error to me but why? Is it not an IS-A relationship? I'd like to thoroughly understand this. Also, as you can see in the code below,

    class A{};
    class B : public A{};
    class C : public A{};
    class D : public B, public C{};
    int _tmain(int argc, _TCHAR* argv[])
    {
    B* b = new D(); // works! ..what?
    }

    If A and D are not an IS-A relationship, why does B and D have to be an IS-A relationship? Or something like this.

    class A{};
    class B : public A{};
    class C : public A{
    public:
    virtual void Func(){
    cout << "Called??";
    }
    };
    class D : public B, public C{
    public:
    virtual void Func(){
    cout << "Called!!";
    }
    };
    int _tmain(int argc, _TCHAR* argv[])
    {
    B* b = new D();
    b->Func(); // Error!
    }

    I understand that I can figure out how this works, but since it's a pretty complicated thing, I'd like to know why this happens, THROUGHLY. So I'd like to know where on the internet web pages I can figure all this out so that I can sleep tight! Thanks in advance.

    modified on Tuesday, August 2, 2011 2:13 AM

    C / C++ / MFC oop question c++ help tutorial

  • Is CString really based on TCHAR?
    D Dean Seo

    I am sorry for this late response. Thank you for helping me. You are the best! Thank you again.

    C / C++ / MFC question c++ help announcement

  • Is CString really based on TCHAR?
    D Dean Seo

    Rajesh R Subramanian wrote:

    I recommend that you read the 3 articles I linked you to, and that will clear up a lot of your doubts.

    I read those 3 articles all the way through and it did help. Thank you. I will print out those articles and read again anytime I need.

    Rajesh R Subramanian wrote:

    That code may compile, but it may or may not work depending on what you intend to do with the _tstr variable.

    By the way, in that case, the thing is that that code doesn't even comfile and it occurs an 'casting failed' error. So I just made a simple example that claify why this happens.

    class A{
    public:
    // I didn't allocate any block of memory on m_WideCharacter to make it simpler.
    const wchar_t* m_WideCharacter;

    operator const wchar\_t\*() const{
    	return m\_WideCharacter;
    }
    

    };
    int _tmain(int argc, _TCHAR* argv[])
    {
    A aaa;
    wchar_t* _WideCharacter = aaa; // error-the operator method can't be called.
    wchar_t* _WideCharacter = (wchar_t*)aaa // error-the operator method can't be called.
    wchar_t* _WideCharacter = (wchar_t*)(const wchar_t*)aaa // works!
    return 0;
    }

    I think I just misunderstood how const and operator() that returns const value in C++ works. To make operator const wchar_t*() const return the value, we definitely need the type casting (const wchar_t*) first, otherwise the compiler wouldn't understand if the operator method in class A can be possibly called. And that is what (const wchar_t*) is for. That's it. That is why in that MFC based code I need to write (LPCTSTR*) because CString only has operator PCXSTR(), which is the same as operaotr const wchar_t*(), and the only way that the operator PCXSTR() is called is to write (LPCTSTR*) for type casting. Am I correct? Or am I not clear enough???

    modified on Friday, July 29, 2011 1:52 AM

    C / C++ / MFC question c++ help announcement

  • Is CString really based on TCHAR?
    D Dean Seo

    Hi, good to see you again.

    Rajesh R Subramanian wrote:

    That's not acceptable. _tstr is a pointer to a char (or wchar_t based on your build). But, _str is a CString variable and so, this conversion won't work.

    CString is a class using a wchar_t* to store the contents, and TCHAR is wchar_t. CSimpleStringT has "operator PCXSTR();", and PCXSTR in Unicode circumstance means LPCWSTR which is also wchar_t*. So if CSTring uses wchar_t and has a perfect method(operator PCXSTR()) to return wchar_t type, why can't I get it using TCHAR* (which is also wchar_t*) I think at least this code below has to work, whether it is safe to use or not.

    CString _str = TEXT("ABCD");
    TCHAR* _tstr = (TCHAR*)_str;

    Thank you for helping me this time again by the way.

    C / C++ / MFC question c++ help announcement

  • Is CString really based on TCHAR?
    D Dean Seo

    Hi. I wrote a simiral question before but I feel like I am still confused. I am compiling in Unicode and I know that in Unicode circumstance CString is allocated with TCHAR as you see below.

    typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;

    So obviously CString has nothing to do with LPCTSTR, which is const char *, or any other type, but TCHAR. However, when I try to do this code below it occurs an error.

    CString _str = TEXT("ABCD");
    TCHAR* _tstr = _str;

    The correct version of the code above should be like this.

    CString _str = TEXT("ABCD");
    TCHAR* _tstr = (TCHAR*)(LPCTSTR)_str;

    There are two type castings, to LPCTSTR and then to TCHAR*, even though CString is defined with TCHAR type. I'd like to know why this weird conversion happens from the operator overloading's view of CStringT, and CSimpleStringT and also the template structure of all the classes related to CString. If I am asking too much to answer in a few sentences, any web pages' link that explain this will be appreciated. Thanks in advance!

    C / C++ / MFC question c++ help announcement

  • Delete doesn't ^delete^ a reference?
    D Dean Seo

    Thanks. This helps me a lot.

    C / C++ / MFC tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups