alexatsearidge
asked on
Derive from CString, but access CString buffer (VS2005)
Hi,
I'm copying code from a VC++ 6.0 project to VS 2005. The code has a string class derived from CString in which some members of CString are accessed (m_pchData, GetData()). The code compiles in VC6 but not in VS2005. I need to be able to do:
class CStringEx : CString
{
public NewFunctionEx()
{
// Access private members of base CString
char* inside_buffer = m_pchData;
// OR
char* inside_buffer = GetData();
}
};
It's just the syntax is tricky since it's a template class and I guess the members are private now...?
I'm copying code from a VC++ 6.0 project to VS 2005. The code has a string class derived from CString in which some members of CString are accessed (m_pchData, GetData()). The code compiles in VC6 but not in VS2005. I need to be able to do:
class CStringEx : CString
{
public NewFunctionEx()
{
// Access private members of base CString
char* inside_buffer = m_pchData;
// OR
char* inside_buffer = GetData();
}
};
It's just the syntax is tricky since it's a template class and I guess the members are private now...?
What is the error which you are getting while compiling it in vs2005?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, when I used GetBuffer() I would get
C2663: 'ATL::CSimpleStringT<BaseT ype,t_bMFC DLL>::GetB uffer': 2 overloads have no legal conversion for 'this' pointer
But today I found I could get over it with ((CString*)this)->GetBuffe r().
We'll see if it works, but before I can compile, I need to solve one more error. The code I'm using calls a method AllocCopy() that evidently allocates a string and copies a substring from an existing string to it. There is no definition for this method anywhere in the project, so I'm wondering if AllocCopy was ever a CString method?
C2663: 'ATL::CSimpleStringT<BaseT
But today I found I could get over it with ((CString*)this)->GetBuffe
We'll see if it works, but before I can compile, I need to solve one more error. The code I'm using calls a method AllocCopy() that evidently allocates a string and copies a substring from an existing string to it. There is no definition for this method anywhere in the project, so I'm wondering if AllocCopy was ever a CString method?
It seems it was a protected member function in CString