長さ、大きさ、サイズ(メモリ量)を表現する型として用いるもので、sizeof演算子が返す符号なしの整数型(unsigned int)である。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// sizeof.cpp | |
// CplusplusPractice | |
// | |
// Created by masai on 2015/05/21. | |
// Copyright (c) 2015年 masai. All rights reserved. | |
// | |
#include <iostream> | |
using namespace std; | |
template<class ... T> | |
struct S{ | |
static const size_t count = sizeof...(T); | |
}; | |
int main(){ | |
// int型で確保されるメモリサイズを出力 | |
cout << sizeof 1 << endl; | |
int a = 2; | |
// sizeofに与えられた式は評価されないため、後に出力するaは2のまま | |
cout << sizeof ++a << endl; | |
cout << a << endl; | |
// 式でなく、型を与えても良い | |
cout << sizeof(int) << endl; | |
cout << sizeof(float) << endl; | |
cout << sizeof(double) << endl; | |
// 可変長引数の個数を取得する場合 | |
S<int, char, double> t; | |
cout << t.count << endl; | |
} |
0 件のコメント:
コメントを投稿