Solved

Derive from CString, but access CString buffer (VS2005)

Posted on 2007-04-09
4
1,289 Views
Last Modified: 2013-12-14
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...?
0
Comment
Question by:alexatsearidge
  • 2
4 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18878397
What is the error which you are getting while compiling it in vs2005?
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 500 total points
ID: 18880330
I think these changes happened in the mfc release with VS2003.
m_pchData is changed to m_pszData and made private. GetData is private. You will have to use GetBuffer to get to the buffer.
0
 

Author Comment

by:alexatsearidge
ID: 18882087
Yeah, when I used GetBuffer() I would get

C2663: 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>::GetBuffer': 2 overloads have no legal conversion for 'this' pointer

But today I found I could get over it with ((CString*)this)->GetBuffer().

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?
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 18882633
It seems it was a protected member function in CString
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Device same like our heart 12 75
C++ :Change value from  DisableCMD registry 4 47
how to use laptop or pad camera in vb.net windows application 2 49
Syntax Error 2 44
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now