c++98 初始化的一些例子

/// 各种形式的初始化
const int x(5);           ///< 直接初始化
const int y = 5;          ///< copy构造初始化
int arr[] = {
    
    1, 2, 3};    ///< 大括号初始化
struct Point{
    
    int x, y;};
const Point p = {
    
    1, 2};   ///< 大括号初始化
class PointX
{
    
    
public:
    PointX(int x, int y);
private:
    int x, y;
};
const PointX px(1, 2);    ///< 构造函数初始化
std::vector< int> vec(arr, arr+3); ///< 从别的容器初始化

猜你喜欢

转载自blog.csdn.net/wx_assa/article/details/104341664