You are using a version without Ads of this website. Please, consider donating:

### Problem calling template functions

How do I call these functions from Mechanical.h???

Mechanical.h
 ``1234567891011121314`` ``````#ifndef MECHANICAL_H_ #define MECHANICAL_H_ class statics { public: template struct Inertia_types { T Rec(T _x, T _y); T Tri(T _x, T _y); void Entity(T _x[], T _y[]); } momentOfInertia; } Static_func; #endif ``````

Mechanical.cpp
 ``123456789101112131415161718192021222324252627282930313233`` ``````#include #include "Mechanical.h" template T statics::Inertia_types::Rec(T _x, T _y) { double _val = (1.0/12) * _x * pow(_y, 3); return _val; } template T statics::Inertia_types::Tri(T _x, T _y) { double _val = (1.0/36) * _x * pow(_y, 3); return _val; } template void statics::Inertia_types::Entity(T _x[], T _y[]) { double _val = 0; } ////////////////////////////////////// #include using namespace std; int main() { float i = 1; double n = 1; //cout << Static_func.momentOfInertia.Rec(n,n) << endl; //cout << Static_func.momentOfInertia.Tri(n,n) << endl; system("pause"); return 0; }``````

Im trying to create templated functions which I can apply all data types to except for strings and other types such as wchar. Am I also writing these correctly? This is my first attempt ever doing this so ALL help is greatly appreciated!
try making the struct outside of it and making a pointer to it in the class
Topic archived. No new replies allowed.