Following code compiles without error or warning. But obviously I put an extra Person
in the implementation part. How come this compiles? Actually I also tried to put more Person
but it seems the code almost compiles. But if use one::one::Person::set_name
, gcc will emit error msg.
nm -C person.o result:
0000000000000000 T one::Person::set_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
It seems compile can "fold" class scope, which make multiple class Person
scope into a single class scope
Centos 8 gcc version 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
// header file
#include <string>
namespace one {
class Person {
public:
void set_name(const std::string& name);
void set_age(int age);
private:
std::string name_;
int age_;
};
}
// implementation
#include "person.h"
// extra Person in the following line.
void one::Person::Person::set_name(const std::string& name) {
name_ = name;
}