2022-04-16

Why do I get C4251 with a non-exported member but not function argument/return?

The Microsoft compiler will emit C4251 for something like this, properly complaining that std::string isn't exported:

#include <string>

class __declspec(dllexport) Foo
{
public:
    Foo();
    int whatever();

    std::string s;  // Generates C4251
};

But the compiler doesn't complain when that same un-exported class is used as an argument or return type:

#include <string>

class __declspec(dllexport) Foo
{
public:
    Foo();
    std::string func();  // No warning emitted.
};

Can someone explain why?



No comments:

Post a Comment