I have two versions of Error structure in my library, so I want to use inline namespaces for the versioning.
#pragma once
#include <string>
namespace core {
inline namespace v2 {
struct Error { // <-- new version
int code;
std::string description;
};
}
namespace v1 {
struct Error { // <-- old version
int code;
};
}
}
Here's the sample that illustrates the compilation error that I receive with Visual Studio 2017. Both clang and gcc work fine.
// foo.h
#pragma once
#include "error.h"
namespace core {
class Foo
{
public:
Foo() = default;
~Foo() = default;
void someMethod(Error err);
};
}
// foo.cpp
#include "foo.h"
#include <iostream>
void core::Foo::someMethod(Error err) { // error C2065: 'Error': undeclared identifier
std::cout << err.code << std::endl;
}
Looks like a bug in MSVS or maybe I am missing something. This code works fine without any issues on MSVS:
void core::Foo::someMethod() { // <-- Error is not passed here
Error err;
err.code = 42;
std::cout << err.code << std::endl;
}
Any idea why do I receive this error?