Here is a header file containing an inline variable:
// inline.hpp
#pragma once
#include <iostream>
struct Test {
~Test() { std::cout << "deleted" << std::endl; }
};
inline const Test test;
...included into two .cpp
files:
// usage.cpp
#include "inline.hpp"
// main.cpp
#include "inline.hpp"
auto main() -> int { return 0; }
This program prints "deleted" twice which is unexpected. I thought there was only a single instance of every inline variable, so I was expecting only one "deleted".
Is this a bug of the compiler? Or did I do something wrong?
The code is compiled with VS2017.