请教下大家关于g++ 和 clang++ 的问题
程序代码:
user.hpp #ifndef __User__ #define __User__ #include <string> using std::string; namespace __TrainManage__ { class User { private: string name, sex, address, tel; int age; public: User (); User (string na, string se, string ad, string te, int ag); User (const User & rhs); bool operator== ( User & myuser); const bool operator== ( const User & myuser ) const; }; } #endif user.cpp #include "user.hpp" namespace __TrainManage__ { User::User () {} User::User (string na, string se, string ad, string te, int ag) : name(na), sex(se), address(ad), tel(te), age(ag) { } User::User (const User & rhs) : name(rhs.name), sex(rhs.sex), address(rhs.address), tel(rhs.tel), age(rhs.age) { } bool User::operator== ( User & myuser ) { return name == myuser.name && sex == myuser.sex && age == myuser.age && tel == myuser.tel && address == myuser.address ? 1 : 0; } const bool User::operator== ( const User & myuser ) const { return name == myuser.name && sex == myuser.sex && age == myuser.age && tel == myuser.tel && address == myuser.address ? 1 : 0; } } 这段代码在clang++下可以正常编译通过,而在g++下却报错: user.cpp:8:5: error: prototype for ‘__TrainManage__::User::User(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, int)’ do es not match any in class ‘__TrainManage__::User’ User::User (string na, string se, string ad, string te, int ag) ^~~~ user.hpp:19:9: error: candidates are: __TrainManage__::User::User(const __TrainManage__::User&) User (string na, string se, string ad, string te, int ag); ^~~~ user.hpp:18:9: error: __TrainManage__::User::User(__TrainManage__::User&) User (); ^~~~ user.hpp:17:9: error: __TrainManage__::User::User(std::__cxx11::string, std::__cxx11::string, int, std::__cxx11::string, std::__cxx11::string) ^ user.cpp:6:5: error: __TrainManage__::User::User() User::User () 而我必须将构造函数写在头文件user.hpp中,变成 #ifndef __User__ #define __User__ #include <string> using std::string; namespace __TrainManage__ { class User { private: string name, sex, address, tel; int age; public: User () {} User (string na, string se, string ad, string te, int ag) : name(na), sex(se), address(ad), tel(te), age(ag) { } User (const User & rhs) : name(rhs.name), sex(rhs.sex), address(rhs.address), tel(rhs.tel), age(rhs.age) { } bool operator== ( User & myuser); const bool operator== ( const User & myuser ) const; }; } #endif 才可以编译通过。请问下大家这个是什么原因?