473,464 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

templated function with vector

Hello,

I am feeling very confused right now. The following code gives me an
error:

X.h:
template <typename T>
ILuint startImage(vector<vector<T> > imageData);

X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >, std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Am I not using templates correctly? It appears to have the correct
function.

Thank you very much for any assistance I might receive!

- dan elliott
Jul 22 '05 #1
8 1358
Daniel L Elliott wrote:
I am feeling very confused right now. The following code gives me an
error:

X.h:
template <typename T>
ILuint startImage(vector<vector<T> > imageData); ^^^^^^
X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah} ^^^^
test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >, std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Am I not using templates correctly? It appears to have the correct
function.


It appears you don't.

V
Jul 22 '05 #2
On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
Daniel L Elliott wrote:
I am feeling very confused right now. The following code gives me an
error:

X.h:
template <typename T>
ILuint startImage(vector<vector<T> > imageData);

^^^^^^
X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

^^^^

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >, std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Am I not using templates correctly? It appears to have the correct
function.


It appears you don't.

V


I am not above total stupidity. I tried to simplify the example, and
forgot to change ILuint startImage to void X::startImage in the example.

It should read:

X.h:
template <typename T>
void startImage(vector<vector<T> > imageData);

X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >,
std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Thanks anyway.

- dan
Jul 22 '05 #3

"Daniel L Elliott" <dan_elliott_at_cox_dot_net@spam_is_pathetic.com > wrote
in message news:pan.2004.10.29.20.04.27.697158@spam_is_pathet ic.com...
On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
Daniel L Elliott wrote:
I am feeling very confused right now. The following code gives me an
error:

X.h:
template <typename T>
ILuint startImage(vector<vector<T> > imageData);

^^^^^^
X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

^^^^

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference
to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >,
std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Am I not using templates correctly? It appears to have the correct
function.


It appears you don't.

V


I am not above total stupidity. I tried to simplify the example, and
forgot to change ILuint startImage to void X::startImage in the example.

It should read:

X.h:
template <typename T>
void startImage(vector<vector<T> > imageData);

X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference
to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >,
std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Thanks anyway.

- dan


I reckon this is the #1 post to this group.

ALL TEMPLATE CODE MUST GO IN HEADER FILES.

Most startimage out of X.cpp, put it in X.h and all will be well.

Don't books on templates teach this? Where did you learn about templates
that didn't mention this basic fact? And what about all the other people who
post similar problems to yours. Please tell, I'm genuinely curious.

john
Jul 22 '05 #4
On Fri, 29 Oct 2004 21:16:48 +0100, John Harrison wrote:

"Daniel L Elliott" <dan_elliott_at_cox_dot_net@spam_is_pathetic.com > wrote
in message news:pan.2004.10.29.20.04.27.697158@spam_is_pathet ic.com...
On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
Daniel L Elliott wrote:
I am feeling very confused right now. The following code gives me an
error:

X.h:
template <typename T>
ILuint startImage(vector<vector<T> > imageData);
^^^^^^

X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}
^^^^

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference
to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >,
std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Am I not using templates correctly? It appears to have the correct
function.

It appears you don't.

V


I am not above total stupidity. I tried to simplify the example, and
forgot to change ILuint startImage to void X::startImage in the example.

It should read:

X.h:
template <typename T>
void startImage(vector<vector<T> > imageData);

X.cpp:
template<typename T>
void X::startImage(vector<vector<T> > imageData){blah}

test.cpp:
vector<vector<double> > testImage1(10);
X.startImage(testImage1);

gcc 3.3.2 gives the following error:
/home/dane/myLibraries/image/testDriver.cpp:25: undefined reference
to`unsigned X::startImage<double>(std::vector<std::vector<doub le,
std::allocator<double> >,
std::allocator<std::vector<double,std::allocator<d ouble> > > >)'

Thanks anyway.

- dan


I reckon this is the #1 post to this group.

ALL TEMPLATE CODE MUST GO IN HEADER FILES.

Most startimage out of X.cpp, put it in X.h and all will be well.

Don't books on templates teach this? Where did you learn about templates
that didn't mention this basic fact? And what about all the other people who
post similar problems to yours. Please tell, I'm genuinely curious.

john


Hey, thanks for the information. I am not sure how this fact has eluded
me over the years. I even have books on c++ and they don't explictly say
it (although their examples always put definitions in the header).

You need to create a webpage entitled: function templates only belong in
the header and have a bunch of people link to it so dummies like myself
can find it via Google!

- dan

Jul 22 '05 #5
>>
Don't books on templates teach this? Where did you learn about templates
that didn't mention this basic fact? And what about all the other people
who
post similar problems to yours. Please tell, I'm genuinely curious.

john


Hey, thanks for the information. I am not sure how this fact has eluded
me over the years. I even have books on c++ and they don't explictly say
it (although their examples always put definitions in the header).

You need to create a webpage entitled: function templates only belong in
the header and have a bunch of people link to it so dummies like myself
can find it via Google!


I guess its templates dirty little secret, people don't really like to talk
about it.

But it is in the FAQ,
http://www.parashift.com/c++-faq-lit...templates.html

john
Jul 22 '05 #6

Daniel L Elliott wrote:

Hey, thanks for the information. I am not sure how this fact has eluded me over the years. I even have books on c++ and they don't explictly say it (although their examples always put definitions in the header).

You need to create a webpage entitled: function templates only belong in the header and have a bunch of people link to it so dummies like myself can find it via Google!

Maybe even better would be to gather up all kinds of information on
such problems that crop all the time, give it a catchy name like
Frequently Asked Questions or sumpin.

http://www.parashift.com/c++-faq-lit...html#faq-34.12
Brian

Jul 22 '05 #7
On Fri, 29 Oct 2004 13:52:20 -0700, Default User wrote:

Daniel L Elliott wrote:

Hey, thanks for the information. I am not sure how this fact has

eluded
me over the years. I even have books on c++ and they don't explictly

say
it (although their examples always put definitions in the header).

You need to create a webpage entitled: function templates only belong

in
the header and have a bunch of people link to it so dummies like

myself
can find it via Google!

Maybe even better would be to gather up all kinds of information on
such problems that crop all the time, give it a catchy name like
Frequently Asked Questions or sumpin.

http://www.parashift.com/c++-faq-lit...html#faq-34.12
Brian


Brian, Jon, et al.

Thanks for the link. It is full of excellent information. Stuff that I
have been wondering about. Sadly, this webpage did not come up during my
search. Search engines like Google typically use the size and location
of text as a measure of its importance. If this is really such an
annoyance, somebody should devote an entire page to it (no matter how
ugly it is). I know I would have appreciated it.

I also noticed that this is referred to as "the FAQ." Does this imply that
this is the defacto, community C++ FAQ?

Thanks again!

- dan
Jul 22 '05 #8
"Daniel L Elliott" <dan_elliott_at_cox_dot_net@spam_is_pathetic.com >
wrote...
[..]
http://www.parashift.com/c++-faq-lit...html#faq-34.12
Brian


Brian, Jon, et al.

Thanks for the link. It is full of excellent information. Stuff that I
have been wondering about. Sadly, this webpage did not come up during my
search. Search engines like Google typically use the size and location
of text as a measure of its importance. If this is really such an
annoyance, somebody should devote an entire page to it (no matter how
ugly it is). I know I would have appreciated it.

I also noticed that this is referred to as "the FAQ." Does this imply that
this is the defacto, community C++ FAQ?


It is de facto the FAQ for this newsgroup. It definitely is mentioned here
many times, so if you cared to read the newsgroup before posting to it, you
would see it. Also, http://groups.google.com/ is a very good source of
Q that have been A'ed already.

It's too late in comp.lang.c++, but if you ever decide to visit another NG,
try looking for the FAQ right away _before_ posting. It is always a good
idea to read FAQ. Saves you and others tons of time. Saves bandwidth too.

V
Jul 22 '05 #9

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

Similar topics

5
by: Marijn | last post by:
I recently told g++ (3.2) something to the effect of: template <class T> struct test{ typedef int type; }; template <class T> void f(){ test<T>::type i;
5
by: Pete C. | last post by:
I'm trying to make a templated function a friend like this: class cls { ... friend cls func<> (const cls& a, const cls& b); }; template< template<class> class Op> cls func (const cls& a,...
2
by: Thomas Matthews | last post by:
Hi, I would like to create a table (or vector) of pointers to templated functions. 1. How do I declare a typedef of a pointer to a templated function? For example, I have some functions...
3
by: William Payne | last post by:
Consider this (templated) class member function: template<typename Type> void CircularContainer<Type>::insert(const Type& s) { vector<Type>::iterator itr = find(m_elements.begin(),...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
9
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
5
by: Gert Van den Eynde | last post by:
Hi all, It's probably trivial but I can't figure it out... I have a templated class template <typename T, typename uclass A I wish to fill a vector with pointers to objects of class A. I...
3
by: newbie | last post by:
Thanks for helping on this problem suppose I have the following class class MyContent { vector<MyType1 v1; vector<MyType2 v2; } And I have a templated function
4
by: Jim Langston | last post by:
This should illistrate what I am trying to do: template <class T> T SomeFunction( T parm ) { return parm; } template <class T> class SomeClass
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...

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.