 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Active8 Guest
|
Posted: Wed Feb 23, 2005 9:11 am Post subject: 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
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Wed Feb 23, 2005 9:39 am Post subject: Re: Passing STL container to temlate function |
|
|
* Active8:
| Quote: |
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
...
};
template <class T
int Files::load_vector(vector
{
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?
|
|
| Back to top |
|
 |
Active8 Guest
|
Posted: Wed Feb 23, 2005 3:59 pm Post subject: Re: Passing STL container to temlate function |
|
|
On Wed, 23 Feb 2005 09:39:15 GMT, Alf P. Steinbach wrote:
| Quote: | * 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
...
};
template <class T
int Files::load_vector(vector
{
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.
| Quote: | and the word "those" is incorrect;
|
no it isn't.
| Quote: | 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
which generates this error:
"type 'double' unexpected"
--
Best Regards,
Mike
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Wed Feb 23, 2005 11:47 pm Post subject: Re: Passing STL container to temlate function |
|
|
* Active8:
| Quote: | 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
...
};
template <class T
int Files::load_vector(vector
{
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.
| Quote: | 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?
|
|
| Back to top |
|
 |
Active8 Guest
|
Posted: Fri Feb 25, 2005 11:01 pm Post subject: Re: Passing STL container to temlate function |
|
|
On Wed, 23 Feb 2005 23:47:17 GMT, Alf P. Steinbach wrote:
| Quote: |
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
|
|
| Back to top |
|
 |
Active8 Guest
|
Posted: Fri Feb 25, 2005 11:02 pm Post subject: Re: Passing STL container to temlate function |
|
|
Oh yeah. Thanks Alf.
--
Best Regards,
Mike
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|