Hey guys,
Here is what I am doing:
Now when I call this function as func<somestruct>(st); I get a compile time error? I am I calling the function wrongly?Code:template <typename T> void func(vector<T> vec) { .. .. .. }
Hey guys,
Here is what I am doing:
Now when I call this function as func<somestruct>(st); I get a compile time error? I am I calling the function wrongly?Code:template <typename T> void func(vector<T> vec) { .. .. .. }
What error? What is "st?" More info please.
st is the type of somestruct
If that's true, then it should give errors. Your function would expect a type of vector<somestruct>.st is the type of somestruct
Post a minimal non-working sample if that doesn't fix it.
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
Before I had a function in a .h file. Once I move it to a cpp file it works fine. I have done it like this:
Is there a way I can keep the function in an external fileCode:template<typename T> void func(vector<T>& vec) { } int main() { vector<int> vec; func(vec); }
Templates must be included in all compilation units that use them. Putting it in a header file and then including the header should be no problem.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Simply moving it to a header file works. But if you put the function declaration in the .h file and definition in .cpp file that does not work.
That is to be expected. Why can't I separate the definition of my templates class from it's declaration and put it inside a .cpp file?But if you put the function declaration in the .h file and definition in .cpp file that does not work.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)