我尝试运行一个简单的 C++ 程序,但我不确定为什么不同的编译器提供不同的输出
#include <iostream>
struct A
{
A() { std::cout << "Object A created" << std::endl; }
friend std::ostream& operator<<(std::ostream& os, const A& a)
{
os << a.str << "\n";
return os;
}
static bool printMe()
{
std::cout << "static bool printMe() of object A" << std::endl;
return true;
}
std::string str{"This is object A"};
};
int main()
{
std::cout << A() << (A::printMe() ? "TRUE" : "FALSE") << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT1:一些编译器提供以下输出:
Object A created
This is object A …Run Code Online (Sandbox Code Playgroud) c++ ×1