Click to See Complete Forum and Search --> : Deriving a class from CString


April 20th, 1999, 01:59 PM
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.

Rich Peters
April 21st, 1999, 10:13 PM
You need to create some suitable constructors. You have none. see CString for the ones you will want to have.

Franky Braem
April 22nd, 1999, 02:15 AM
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)
{
}

April 22nd, 1999, 08:29 AM
Thanks that seemed to work...... Thank you very much.... This is an excellent site.

-Larry