为什么C ++忽略名称空间?

时间:2020-10-21 09:43:54

标签: c++

尝试使用clang和GCC进行C ++版本98、04、11、17、20(部分)的编译。

test.hpp

namespace test {

struct test_struct {};

void test_function(const test_struct& x);

}

test.cpp

#include "test.hpp"

void test::test_function(const test::test_struct& x) { }

main.cpp

#include "test.hpp"

#include <iostream>

int main() {
    test::test_struct x;
    std::cout << test_function(x) << std::endl;
}

我希望它会报告一个错误,指出在test_function中被调用时未声明main

但是,它可以编译并正常运行。此外,当更改test_function使其使用int而不是struct时,确实会报告错误。

0 个答案:

没有答案