3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

可変引数テンプレートで多重継承して新しい型を作るメモ

Posted at

型を組み合わせた型を作るのに手作業だとめんどい。
テンプレートを使えば楽にできるらしい。
やってみよう
##コード例##


#include <iostream>

// 頂点位置
class vec3_t
{
    float v[3];
};

// 色
class color4_t
{
    float c[4];
};

// テクスチャ座標
class uv_t
{
    float uv[2];
};

template < class... Bases >
    class compound_job : public Bases... {};

using vb_00_t = compound_job< vec3_t, color4_t >;
using vb_01_t = compound_job< vec3_t, uv_t >;

int main()
{
    using namespace std;
    
	cout << "sizeof( vec3_t )  " << sizeof( vec3_t )   << endl;
	cout << "sizeof( color4_t )" << sizeof( color4_t ) << endl;
	cout << "sizeof( uv_t )	   " << sizeof( uv_t )	   << endl;
    cout << "sizeof( vb_00_t ) " << sizeof( vb_00_t )  << endl;
    cout << "sizeof( vb_01_t ) " << sizeof( vb_01_t )  << endl;
    
    return 0;
}

結果


Start

sizeof( vec3_t )  12
sizeof( color4_t )16
sizeof( uv_t )	   8
sizeof( vb_00_t ) 28
sizeof( vb_01_t ) 20

0

Finish

##参照##
Faith and Brave 様
可変引数テンプレートで多重継承

コード確認。
[Wandbox]三へ( へ՞ਊ ՞)へ ハッハッ

C++11の文法と機能
可変引数テンプレート(Variadic Templates)

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?