gpt4 book ai didi

c++ - 为什么 C++ 允许变量名和类名相同?

转载 作者:可可西里 更新时间:2023-11-01 17:35:56 26 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <vector>

using namespace std;

typedef int UINT4;

class Hack
{};

Hack& operator <(Hack& a , Hack& b)
{
std::cerr << "1";
return a;
}

Hack& operator >(Hack& a, Hack& b)
{
std::cerr << "2";
return a;
}

int main()
{
Hack vector; // It SHOULD be OK!?
Hack UINT4; // It SHOULD be OK!?
Hack v;
Hack Hack; // It SHOULD be OK!?
Hack = v; // It SHOULD be OK!?

// Please stop to think for a moment: What will the following output?
vector<UINT4> v;

// Oh, my god! The whole world goes mad!

return 0;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com