c++ - non datatype template parameter, more specialization generated? -


my code is:

#include <iostream>  using namespace std;   template <typename t, int x>  class test {    private:     t container[x];    public:     void printsize();  }; template <typename t, int x> void test<t,x>::printsize() {     cout <<"container size = "<<x <<endl; }   int main() {     cout << "hello world!" << endl;     test<int, 20> t;     test<int, 30> t1;      t.printsize();     t1.printsize();     return 0; } 

question:

  1. how many specialization generated?. if understand correctly , generates 2 specializations 1 <int, 20> , <int, 30>. kindly correct if understanding wrong?
  2. is there way see/check number of specializations generated reverse engineering?

1) yes, 2 instantiations generated compiler, linker might merge functions identical generated code (using whole program optimization e.g.), cute way reduce code bloat.

2) see question explained how gcc can generate template instantiation output.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -