揮発性のメモ2

http://d.hatena.ne.jp/iww/

2016-10-06から1日間の記事一覧

構造体に関数を書く

C++

#include <iostream> using namespace std; typedef struct { int a; int b; int getA(){ return a; } int getB(){ return b; } } hoge_t; int main() { hoge_t aa = {}; aa.a = 123; cout << aa.getA() << endl; // 123 cout << aa.getB() << endl; // 0 return 0; }</iostream>