c++ - Get template parameter from file -


i have 2 classes:

  1. a non-type templated class foo
  2. a non-templated class bar contains member of foo, template parameter should read file.

from (i think) know, doesn't work because template parameters of non-templated class set @ compile-time, need static consts. don't see how can achieve that, since evaluation (i.e. reading file, extracting value) has happen before can provide parameter value. nonetheless, there way achieve similar?

i want avoid templating second class since user has (in theory) no knowledge of file, should looked when program executed. file not change during run-time.

the situation this:

// templated class template <int a> class foo {   public:       foo() : a_(a) {};       void print () { std::cout << "the value of : " << a_ << std::endl; }   private:       int a_; };  // non-templated class // won't work, showing idea: class charlie {     public:         charlie() {             = loadfromfile("myfile");         }         void print () {              std::cout << "called c: " << std::endl;             c_.print();          }      private:         int a;         foo<a> c_; }; 

thanks!

you cannot have template parameters read file, or otherwise determined @ runtime.

template paramters, inherently need deduced/calculated @ compile time. no other way, sorry!

the idea of template parameters can optimized @ compile time, resolving them can't defered runtime.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -