Click here to Skip to main content
16,012,025 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC without a dialog or view? Pin
Erik Funkenbusch11-Dec-00 12:17
Erik Funkenbusch11-Dec-00 12:17 
GeneralMinimized Window doesnot show up Pin
8-Dec-00 9:38
suss8-Dec-00 9:38 
GeneralHelp with string class - return char * Pin
Christian Graus7-Dec-00 12:04
protectorChristian Graus7-Dec-00 12:04 
GeneralRe: Help with string class - return char * Pin
Michael Dunn7-Dec-00 13:35
sitebuilderMichael Dunn7-Dec-00 13:35 
GeneralRe: Help with string class - return char * Pin
Christian Graus7-Dec-00 14:04
protectorChristian Graus7-Dec-00 14:04 
GeneralRe: Help with string class - return char * Pin
Erik Funkenbusch8-Dec-00 10:20
Erik Funkenbusch8-Dec-00 10:20 
GeneralRe: Help with string class - return char * Pin
Christian Graus8-Dec-00 12:22
protectorChristian Graus8-Dec-00 12:22 
GeneralRe: Help with string class - return char * Pin
Erik Funkenbusch8-Dec-00 18:25
Erik Funkenbusch8-Dec-00 18:25 
I take it you mean you want to create a class with the same interface as CString, which is portable.

You can mostly achieve this by using a std::string as a member of CGString class, then set up forwarding functions that call members in string, or alternatively you can use private inheritance of std::string. This will make it so that you can't assign a CGString pointer to a a std::string pointer.

However, it won't be possible to completely duplicate CStrings functionality for a variety of reasons, especially if you provide a virtual destructor.

If you look at CString, you'll also see that it doesn't provide a virtual destructor. The reason is simple:

You can cast a CString to a char* and use it as if it were an array of characters. It does this by making the array pointer the first member in the class, thus a pointer to the CString is also a pointer to it's first member. In classes that have vtables though, the pointer to the class is also the pointer to the vtable, which would not work.

This isn't exactly good behavior though, so you might just want to say "You can't do that in my CGString", which would be fine unless you have existing code which expects that.

As far as external functions go, I think you're stuck in "everything has to be an object" mentality. Look at the standard C++ library. It provides all kinds of functions called algorithms that work on generic objects. These algorithms aren't part of the objects themselves, and it's still object oriented. You don't have to make everything a member for it to be OO. This is the biggest mistake most people make when using C++, too much encapsulation.

The things you mention are easily accomplished with external functions and std::string. You want to make lower, just use:

std::string s("ThIs Is A mIxEd CaSe StRiNg");
std::transform(s.begin(), s.end(), s.begin(), std::tolower);

Format is indeed handy, but it's simple enough to create your own format function that does the same thing using sprintf.

GeneralRe: Help with string class - return char * Pin
Christian Graus9-Dec-00 9:42
protectorChristian Graus9-Dec-00 9:42 
GeneralRe: Help with string class - return char * Pin
Erik Funkenbusch9-Dec-00 12:54
Erik Funkenbusch9-Dec-00 12:54 
GeneralRe: Help with string class - return char * Pin
Christian Graus9-Dec-00 21:28
protectorChristian Graus9-Dec-00 21:28 
GeneralRe: Help with string class - return char * Pin
Erik Funkenbusch11-Dec-00 12:25
Erik Funkenbusch11-Dec-00 12:25 
GeneralRe: Help with string class - return char * Pin
Christian Graus8-Dec-00 12:58
protectorChristian Graus8-Dec-00 12:58 
GeneralRe: Help with string class - return char * Pin
Erik Funkenbusch8-Dec-00 18:26
Erik Funkenbusch8-Dec-00 18:26 
Generaldisable one ActiveX function Pin
7-Dec-00 7:57
suss7-Dec-00 7:57 
GeneralRe: disable one ActiveX function Pin
SAWilde7-Dec-00 23:03
SAWilde7-Dec-00 23:03 
GeneralRe: disable one ActiveX function Pin
8-Dec-00 6:23
suss8-Dec-00 6:23 
GeneralDesktop icons and their labels Pin
Daníel B. Sigurgeirsson7-Dec-00 4:46
Daníel B. Sigurgeirsson7-Dec-00 4:46 
GeneralRe: Desktop icons and their labels Pin
Christian Graus7-Dec-00 12:07
protectorChristian Graus7-Dec-00 12:07 
GeneralRe: Desktop icons and their labels Pin
Daníel B. Sigurgeirsson11-Dec-00 0:17
Daníel B. Sigurgeirsson11-Dec-00 0:17 
GeneralChanging text color on Buttons created on the fly Pin
Ishai Shotten7-Dec-00 4:27
Ishai Shotten7-Dec-00 4:27 
GeneralCRichEditView context menu Pin
7-Dec-00 1:42
suss7-Dec-00 1:42 
GeneralRe: CRichEditView context menu Pin
SAWilde7-Dec-00 23:23
SAWilde7-Dec-00 23:23 
GeneralToolBar Pin
6-Dec-00 17:04
suss6-Dec-00 17:04 
GeneralRe: ToolBar Pin
Michael Dunn6-Dec-00 17:32
sitebuilderMichael Dunn6-Dec-00 17:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.