function - My template code in C++ is generating odd errors I can't seem to resolve. -


i having errors appear in code , can't figure them out. reduced code down basic simple functions/class calls still have issues this.

#include <iostream> using namespace std;  template <class t>   class fc { private:      double netprofit, costofinvest;     double curras, invent, curliab; public:       void roi(double np, double ci)     {      netprofit = np; costofinvest = ci;     }      double getroi()     {      return (netprofit - costofinvest) / costofinvest;     }      void atr(double ca, double inv, double cl)     {      curras = ca; invent = inv; curliab = cl;     }      double getatr()     {     return (curras - invent) / curliab;     }  };   int main() {  fc roi, acidtestratio;    roi.roi(27, 288);  cout << roi.getroi() << endl;   acidtestratio.atr(77, 2l, 344);  cout << acidtestratio.getatr() << endl;   return 0; } 

the errors this:

in function 'int main()': 39:22: error: missing template arguments before 'roi' 41:2: error: 'roi' not declared in scope 44:2: error: 'acidtestratio' not declared in scope 

you need give template argument ´t´:

fc<float> roi, acidtestratio;  

but alain points out, not using t yet, may instead remove template <class t> beginning of code instead.

alternatively, may want use t type of members instead of double:

template <class t>  class fc { private:      t netprofit, costofinvest;     t curras, invent, curliab; public:       void roi(t np, t ci)     {      netprofit = np; costofinvest = ci;     }      t getroi()     {      return (netprofit - costofinvest) / costofinvest;     }      void atr(t ca, t inv, t cl)     {      curras = ca; invent = inv; curliab = cl;     }      t getatr()     {     return (curras - invent) / curliab;     } }; 

update: full example here


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -