掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
インクルードファイルを未公開としたい (ID:60402)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
クラス宣言のみして、CTestクラスではCTemplateクラスのメンバ変数を ポインタで定義する。 例えば以下のように。 //---------- template.h ----- #include <iostream> template< class T > class CTemplate { public: void print() const { std::cout << "CTemplate" << std::endl; } }; //---------- test.h ----- template< class T > class CTemplate; // 宣言のみ class CTest { CTemplate<int>* m_test; // ポインタで持つ(実体ではもてない) public: CTest(); ~CTest(); void print() const; }; //---------- test.cpp ----- #include "test.h" #include "template.h" // 実体を扱うため CTest::CTest() { m_test = new CTemplate< int >(); } CTest::~CTest() { delete m_test; } void CTest::print() const { m_test->print(); } //---------- main.cpp ----- #include "test.h" int main() { CTest t; t.print(); return 0; }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.