Created
May 21, 2015 14:09
-
-
Save MasazI/78553ff0ca4f96aae2d9 to your computer and use it in GitHub Desktop.
sizeof.cpp
This file contains hidden or 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment