472,353 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Passing STL container to temlate function


vector<double> signal;
vector<double>::iterator iter;

in_file.load_vector(signal);
in_file.load_vector(signal.begin());

those calls give the compiler error:
"could not deduce template argument for 'T'"

the infile object is a non-template class with a template function
in it

class Files
{
...
template <class T>
load_vector(vector<T>& sig);
...
};

template <class T>
int Files::load_vector(vector<T>& sig)
{
return 0;
}

What can I do about this?

TIA
--
Best Regards,
Mike
Jul 23 '05 #1
5 1906
* Active8:

vector<double> signal;
vector<double>::iterator iter;

in_file.load_vector(signal);
in_file.load_vector(signal.begin());

those calls give the compiler error:
"could not deduce template argument for 'T'"

the infile object is a non-template class with a template function
in it

class Files
{
...
template <class T>
load_vector(vector<T>& sig);
...
};

template <class T>
int Files::load_vector(vector<T>& sig)
{
return 0;
}

What can I do about this?


To do: be more precise (most of the information you've provided is
irrelevant, and the word "those" is incorrect; with the irrelevant
information removed and that word corrected you have your solution).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
On Wed, 23 Feb 2005 09:39:15 GMT, Alf P. Steinbach wrote:
* Active8:

vector<double> signal;
vector<double>::iterator iter;

in_file.load_vector(signal);
in_file.load_vector(signal.begin());

those calls give the compiler error:
"could not deduce template argument for 'T'"

the infile object is a non-template class with a template function
in it

class Files
{
...
template <class T>
load_vector(vector<T>& sig);
...
};

template <class T>
int Files::load_vector(vector<T>& sig)
{
return 0;
}

What can I do about this?
To do: be more precise (most of the information you've provided is
irrelevant,


Other than the compiler (VC++) what info *would* you consider
"relevant"? The code I posted is all the code (except compiler
supplied headers) pertaining to the template function that won't
compile. I included the call that I used when I tried passing an
iterator.
and the word "those" is incorrect;
no it isn't.
with the irrelevant
information removed and that word corrected you have your solution).


calls give the compiler error:
"could not deduce template argument for 'T'"

Doesn't help. AFAICT, the syntax is right and it should work like
any other code written the same way like this code from an online
ref.

template <class T>
T GetMax (T a, T b) {
return (a>b?a:b);
}

int main () {
int i=5, j=6, k;
long l=10, m=5, n;
k=GetMax(i,j);
n=GetMax(l,m);
cout << k << endl;
cout << n << endl;
return 0;
}

That ref also shows this calling convention:

in_file.load_vector<double>(signal);

which generates this error:

"type 'double' unexpected"

--
Best Regards,
Mike
Jul 23 '05 #3
* Active8:
On Wed, 23 Feb 2005 09:39:15 GMT, Alf P. Steinbach wrote:
* Active8:

vector<double> signal;
vector<double>::iterator iter;

in_file.load_vector(signal);
in_file.load_vector(signal.begin());

those calls give the compiler error:
"could not deduce template argument for 'T'"

the infile object is a non-template class with a template function
in it

class Files
{
...
template <class T>
load_vector(vector<T>& sig);
...
};

template <class T>
int Files::load_vector(vector<T>& sig)
{
return 0;
}

What can I do about this?
To do: be more precise (most of the information you've provided is
irrelevant,


Other than the compiler (VC++) what info *would* you consider
"relevant"?


The signature of the function called, the call, the error message,
and possibly also the compiler (in this case it isn't compiler-specific
but you couldn't know that), for best effort the sig+call packaged as
a small program that one can copy, paste and compile.

The code I posted is all the code (except compiler
supplied headers) pertaining to the template function that won't
compile. I included the call that I used when I tried passing an
iterator.
and the word "those" is incorrect;


no it isn't.


Well, it is. ;-)

Consider the signature of your function again.

Hint 1: in there you'll see the word "vector". Hint 2: one of your
calls doesn't pass a "vector". Hint 3: the other one does.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #4
Oh yeah. Thanks Alf.
--
Best Regards,
Mike
Jul 23 '05 #5
On Wed, 23 Feb 2005 23:47:17 GMT, Alf P. Steinbach wrote:


Consider the signature of your function again.

Hint 1: in there you'll see the word "vector". Hint 2: one of your
calls doesn't pass a "vector". Hint 3: the other one does.


I finally found that, duh!

I'll post a small complete module next time, but notice that I was
correct in asuming that what I posted was enough :)
--
Best Regards,
Mike
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in...
2
by: Active8 | last post by:
Maybe it's been so long that I forgot something but I can't remember the solution to this compiler error: error C2039: '__ctor' : is not a member...
2
by: Tom Lee | last post by:
Hi all, I have the following problem and I cannot solve it. If anyone can help me solve this problem. I use the following code...
2
by: Yama | last post by:
Hi, Simple question: Is there a way to a value from client-side to server-side upon a click? function _getReport(ReportName) {...
3
by: KK | last post by:
Hello all, I have several classes binded by one common interface - say 'sum' interface which calculates the sum of all the class elements of type...
2
by: bubzilla | last post by:
hi got a little prob with data types. I´m reading data from a socket in to a unsigned char buf; . Now, lets say there are 60Bytes written into...
5
by: pkoniusz | last post by:
Hello everyone. The problem may be obvious, though I'm a bit puzzled by the error LNK2028 when attempting to utilize my static library. The all...
6
by: poorboywilly | last post by:
I've been unable to find any information on this through any search engines. Is there any way to pass an unnamed (temporary) array to a function?...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.