Re: What makes a class view as an embed object

From: Robert W Hand (rwhand_at_NOSPAMoperamail.com)
Date: 10/14/04


Date: Thu, 14 Oct 2004 05:10:12 -0400

On Thu, 21 Oct 2004 13:40:31 -0400, "Denis @ Work" <denisco@ica.net>
wrote:

>I have develop a string type class, I would like to know what would make my
>class object view in the debugger as a char *;

Sorry, that would depend on your debugger. You would get better
answers by asking in a group devoted to your compiler.

>Plus when I use that class object in a parameter such as printf( to be
>seeing as a char string.

It is useful to give a code example. I assume that you are doing
something like:

printf("%s\n", myClassObject);

Unless there is a conversion specified in your class definition, I
cannot see how that would work. In many string classes, such as
std::string, there are converters to pointer to const char.

printf("%s\n", myClassObject.c_str());

The second argument returns a pointer to const char that contains the
value of the string class object.

>I am comparing my class with the string and the mfc CString class but it is
>not obvious how it does the trick.

Again, code is useful. I assume that you are writing something like
this:

std::string stdString;
MyString mystring;
mystring == stdString;

Have you defined an operator ==() in your string class? Does it
compare to std::string and CString (in both directions)?

>Does it have to do with private public and protected member?

Only indirectly. You would need public comparison operators defined
for your class.

-- 
Best wishes,
Bob


Relevant Pages

  • Re: Creating a derived object from a base object
    ... In the case where you can't inherit from the parent, ... How WOULD you write a MyString constructor that takes a string? ... assume that the String class is a black box). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: cast operator
    ... > I have a string class, which is a wrapper for a char * ... Then you pretty much give a const char* to anything expecting a String and it will ... It converts you String class to a const char*. ...
    (comp.lang.cpp)
  • Re: std::string, C strings and c_str()
    ... > Would a simple String class like this help? ... what stands out is that the conversion to char * operator breaks ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Whats wrong ?? LNK2019 error (Unresolved externals)
    ... you should never use char arrays to manipulate strings. ... Always use a string class ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Formatting a string in Java
    ... I looked at Java' String class and StringBuilder ... String s = new MyString('0', ... You can make a MyString that implements CharSequence and has a "filler" constructor, then use that in the constructor ...
    (comp.lang.java.programmer)