I recently copy and pasted a C++ member function from my cpp file into the header and forgot to remove the prefix. So, in the cpp file, I had something like:
int MyClass::Return42() const { return 42; }
and, in my header:
class MyClass {
public:
int MyClass::Return42() const;
};
Now I'm sure I've done that before and had the compiler complain bitterly that it was not allowed, requiring the removal of the class prefix in the header. In fact g++ 5.4.0
complains about it under Linux regardless of which ISO standard I target (11 through 17), using a single file (though -fpermissive
will turn this into a warning rather than an error):
#include <iostream>
class MyClass {
public:
int MyClass::Return42() const;
};
int MyClass::Return42() const { return 42; }
int main() {
MyClass x;
std::cout << x.Return42() << '\n';
}
But I find that my brand new install of VsPro15 appears to allow that.
How do I get Visual Studio to reject this invalid code, given I'd like my code to be portable across different platforms?
I am aware of the suggested solutions involving /permissive-
and /Ze
.
For the first, even with VS2k15 Update 3, entering /permissive-
into the Project properties | C/C++ | Command Line | Aditional Options
field, results in:
2>cl : Command line warning D9002: ignoring unknown option '/permissive-'
For the second, I see:
2>cl : Command line warning D9035: option 'Ze' has been deprecated and will be removed in a future release
but it compiles the errant code anyway.
So I don't believe that either is a viable solution.