473,793 Members | 2,742 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 1971
* 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
4811
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
1753
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
10147
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
1470
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
1597
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
3140
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
2855
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
8900
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
9518
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
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.