Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is part of my code not executed?

I'm using Visual C++ to compile my plug-in for Cinema 4D.

    GeDebugOut("-->");
    subroot = NULL;
    head = NULL;
    tail = NULL;
    success = PolygonizeHierarchy(source, hh, head, tail, &subroot, malloc);
    if (!success) {
        /* .. */
    }
    String str("not set.");
    if (subroot) {
        GeDebugOut("yes");
        str = "yes!";
        GeDebugOut("Subroot name: " + subroot->GetName());
    }
    else {
        GeDebugOut("no");
        str = "no!";
    }
    GeDebugOut("Is there a subroot?   " + str);
    GeDebugOut("<--");

The expected output is the following:

-->
yes
Subroot name: Cube
Is there a subroot?  yes
<--

(or the same with "no" instead.) But I get

-->
yes
<--


Why are two prints missing here?


This is the declaration of GeDebugOut.

void GeDebugOut(const CHAR* s,  ...);
void GeDebugOut(const String& s);

The String class is concatenateable. It overloads the + operator.

String(void);
String(const String& cs);
String(const UWORD* s);
String(const CHAR* cstr, STRINGENCODING type = STRINGENCODING_XBIT);
String(LONG count, UWORD fillch);
friend const String operator +(const String& Str1, const String& Str2);
const String& operator +=(const String& Str);
like image 208
Niklas R Avatar asked Jul 25 '12 15:07

Niklas R


1 Answers

You need to use GeDebugOut like you use printf:

GeDebugOut("Some message =  %s ", whatever);

where whatever is a c-string, i.e its type is char*.

Since an overload of GeDebugOut accepts String type also, then I think you need to use unicode as:

GeDebugOut(L"Is there a subroot?   " + str);
        // ^ note this!

because my suspicion is that if unicode is enabled, then CHAR is basically wchar_t, not char. And because of this, the string concatenation doesn't work, as the string-literal doesn't implicitly get converted into String type, to be passed to + overload.

like image 96
Nawaz Avatar answered Nov 15 '22 04:11

Nawaz