473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Templates Error

Hey guys,
Here is what I am doing:

Code:
Expand|Select|Wrap|Line Numbers
  1. template <typename T>
  2. void func(vector<T> vec)
  3. {
  4.  ..
  5.  ..
  6.  ..
  7. }
  8.  
Now when I call this function as func<somestruct>(st); I get a compile time error? I am I calling the function wrongly?
Aug 8 '07 #1
4 1153
gpraghuram
1,275 Expert 1GB
Hey guys,
Here is what I am doing:

Code:
Expand|Select|Wrap|Line Numbers
  1. template <typename T>
  2. void func(vector<T> vec)
  3. {
  4.  ..
  5.  ..
  6.  ..
  7. }
  8.  
Now when I call this function as func<somestruct>(st); I get a compile time error? I am I calling the function wrongly?
Hi,
I tried something similar and it worked well.
Expand|Select|Wrap|Line Numbers
  1. template<typename T>
  2. void func(vector<T> vec)
  3. {
  4. }
  5.  
  6. int main()
  7. {
  8.     vector<int> f1;
  9.     func(f1);
  10. }
  11.  
Raghuram
Aug 8 '07 #2
When I move the function to the same file it compiles fine. Is there a way I can keep this function in a .h file?
Aug 8 '07 #3
Darryl
86
When I move the function to the same file it compiles fine. Is there a way I can keep this function in a .h file?
If you use the Comeau Compiler, you could use the export keyword, otherwise and unfortunately, most other compiler makers have chosen not to implement it and therefore your template definitions must be in a single file.
Aug 8 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Comeau Compiler, you could use the export keyword,
Really? This is the first I've heard that any compiler supports export templates.

When I move the function to the same file it compiles fine. Is there a way I can keep this function in a .h file?
Put your templates in a header file and include the header as needed.
Aug 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: franky.backeljauw | last post by:
Hello, I have a problem with using a copy constructor to convert an object of a templated class to object of another templated class. Let me first include the code (my question is below): ...
9
by: Fred H | last post by:
I'm currently trying to write a function template that can fill a variable of arbitrary type with 'random' stuff, but I can't seem to get my function template working. In my .h file I've...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
1
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of...
1
by: Rebecca Hoffmann | last post by:
Hi, I have a serious problem while compiling a small project (a part of the Modular Flow Scheduling Middleware: ex1): There are 3 linker errors, all from symbols that point to templates: --...
7
by: Robert Bralic | last post by:
Dear, I wreated a small program that make a linked list of factorials of numbers, I don't have expirience with templates so I will bee thankfull if anybody can make the same with...
11
by: Peter Oliphant | last post by:
Is there any plan to support templates with managed code in the (near) future? For instance, VS.NET 2005... : )
2
by: recover | last post by:
#include <stdio.h> template<class T> class TpHello { public: int GetHash(){return 0;} protected: private: T a;
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
6
by: Josefo | last post by:
Hello all. I am a newbie following the C++ tutorial in : http://www.cplusplus.com/doc/tutorial/templates.html I am unable to succesfully compile any of the examples with templates of this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.