Search code examples
c++wxwidgets

White spaces in naming a class?


I was through the source of wxWidgets when I saw this code

class WXDLLIMPEXP_FWD_CORE wxKeyEvent;

After this they defined a class like this

class WXDLLIMPEXP_FWD_CORE wxKeyEvent : public wxEvent{
//some code
};

As you can see there is a white space, but you cannot have it while naming the class, further I wrote this small code which compiles successfully `

#include <bits/stdc++.h>

using namespace std;

class a
{
public:
    int x;  
};

class a b
{
    // it fails if i add anything there
};

int main()
{
    return 0;
}

This fails to compile when I add something inside class a b. Could you please tell me what's going on?

Thank you!


Solution

  • WXDLLIMPEXP_FWD_CORE is a macro that is supposed to add a (compiler specific) class attribute and expands to __declspec(dllexport) or __declspec(dllimport) depending if used to export or import the class.

    You example class a b { /* ... */ }; is simply invalid syntax,

    Class names cannot contain whitespaces.