Re: cast operator

From: Ron Natalie (ron_at_sensor.com)
Date: 02/17/04


Date: Tue, 17 Feb 2004 15:56:18 -0500


"Ali R." <nospam@nospam.com> wrote in message news:11vYb.207$xD6.30181429@newssvr11.news.prodigy.com...
> Hi guys,
>
> I have a string class, which is a wrapper for a char *
> with a few operators, like +

Sounds like what you want is a converting constructor, like the std::string
class has.

class String {
public:
    String(const char*);
    String();
...
};

Then you pretty much give a const char* to anything expecting a String and it will
be converted.

The operator char*() you defined does the opposite (and is probably ill-advised).
It converts you String class to a const char*.



Relevant Pages

  • Re: Combo Box String to char*
    ... Well, the real problem is most likely that the function should have been a const char *, ... or better still, an LPCTSTR parameter. ... number of characters in the string; if you give a longer value, ...
    (microsoft.public.vc.mfc)
  • Re: Converting BSTR to char*
    ... First, you should realize that a BSTR is a wide character string, whereas char* is a narrow string. ... This actually maintains both a narrow and wide string internally, and has cast operators for both const char* and const wchar_t*. ...
    (microsoft.public.vc.language)
  • Re: case insentisive file search
    ... CopyStringPrefix(const char *String, size_t PrefixLength) ... FileName = CopyString; ...
    (comp.lang.c)
  • Re: What makes a class view as an embed object
    ... In many string classes, such as ... there are converters to pointer to const char. ... value of the string class object. ... MyString mystring; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: String Comparision
    ... int comp(const char *s, const char *t) { ... int comp(const restrict char *s, const char *t) { ... It could be argued that a lack of a string is less than an empty string, and that if both elements are "lack of string" they are of the same value. ...
    (comp.lang.c)