473,704 Members | 5,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing STL container to temlate function


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

in_file.load_ve ctor(signal);
in_file.load_ve ctor(signal.beg in());

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(vec tor<T>& sig);
...
};

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

What can I do about this?

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

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

in_file.load_ve ctor(signal);
in_file.load_ve ctor(signal.beg in());

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(vec tor<T>& sig);
...
};

template <class T>
int Files::load_vec tor(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_ve ctor(signal);
in_file.load_ve ctor(signal.beg in());

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(vec tor<T>& sig);
...
};

template <class T>
int Files::load_vec tor(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_ve ctor<double>(si gnal);

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_ve ctor(signal);
in_file.load_ve ctor(signal.beg in());

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(vec tor<T>& sig);
...
};

template <class T>
int Files::load_vec tor(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
4798
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 place of an array of base class object. Since I am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
2
1751
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 of 'GFX<class T>' error C2935: 'GFX<class T>' : template-class-id redefined as a global function gfx.h #include <canvas.h>
2
10142
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 <%#DataBinder.Eval(Container.DataItem, "Property")%> to display Property from database. How do I dynamically change the value "Property" to another one say "Name" to display the Name from database or to any other variable that I want. Thanks.
2
1468
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) { alert(ReportName); } <asp:datalist id="dlReports" runat="server"> <itemtemplate>
3
1592
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 'int'. class Alphabet { int _a; int _b; int _c;
2
3136
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 the array( but it is always different). Now i want to give the bytes to a other class like: pushControlPacket(buf);
5
2850
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 methods of the class defined within that library do not pose any troubles, but template based methods. Let's say this is a header: class LooseFunctions {
6
8884
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? e.g. void f0(const int ar); void f1(const int ar); f0( {1, 2, 3, 4, 5} ); //does not compile
0
8764
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8677
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9020
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4694
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2468
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.