1
1

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.

template class の インスタンス呼び出し

1
Posted at
callTemplateClassConstractor.cpp
# include <vector>
# include <iostream>

template <class T>
class Hoge {
    public:
        Hoge();
        ~Hoge(){};
        void print();
    private: std::vector<T> t_vector;
};

class Fuga {
    public:
        Fuga():a_(3){};
        int a_;
    private:
};

template<class T>
Hoge<T>::Hoge(){
    int size = 50;
    t_vector.resize(size);
    for(int i = 0; i < t_vector.size();++i){
        t_vector[i] = T();
    }
};

template<class T>
void Hoge<T>::print(){
    std::cout << t_vector.size() << std::endl;
}

int main() {
    Hoge<Fuga> h;
    h.print();
    return 1;
}

T();で呼び出しできる

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?