1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
namespace A
{
class distance // C++98, C++11, C++14, C++17
{
private:
int feet ;
float inches ;
public:
distance() : feet(0), inches(0) {}
distance( int ft, float in ) : feet(ft), inches(in) {}
};
}
namespace B
{
class distance // C++98, C++11, C++14, C++17
{
private:
int feet ;
float inches ;
public:
// also the default constructor
explicit distance( int ft = 0, float in = 0 ) : feet(ft), inches(in) {}
};
}
namespace C
{
class distance // requires C++11 or later
{
private:
int feet = 0 ;
float inches = 0 ;
public:
constexpr distance() = default ;
constexpr explicit distance( int ft ) : feet{ft} {}
constexpr distance( int ft, float in ) : feet{ft}, inches{in} {}
};
}
|