CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    Deriving a class from CString

    I derived a new class from CString. Here is my code:
    //ScriptXSourceString ~ SXSrcS
    class SXSrcS : public CString
    {

    public:
    // SXSrcS();
    // ~SXSrcS();
    getRVal(CString &, CString);

    };
    #endif

    I then creat an object:
    SXSrcS temp = "this is a test";

    I get the following error:

    OP1QuestionList.cpp(441) : error C2440: 'initializing' : cannot convert from 'char [15]' to 'class SXSrcS *'

    My question is what is the deal..How come I am getting this error.





  2. #2
    Join Date
    Apr 1999
    Posts
    33

    Re: Deriving a class from CString

    You need to create some suitable constructors. You have none. see CString for the ones you will want to have.


  3. #3
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Deriving a class from CString

    When you derive a class from another class, you can use the members and methodes from that class. The constructors are the exception. You have to specify your own constructors(which can make use of the constructors of the base class)

    Example:

    SXSrcS::SXSrcS(const char *pszChar) : CString(pszChar)
    {
    }





  4. #4
    Guest

    Re: Deriving a class from CString

    Thanks that seemed to work...... Thank you very much.... This is an excellent site.

    -Larry


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured