 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Daniel L Elliott Guest
|
Posted: Fri Oct 29, 2004 7:54 pm Post subject: 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 imageData);
X.cpp:
template<typename T>
void X::startImage(vector<vector imageData){blah}
test.cpp:
vector<vector 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
std::allocator, std::allocator<std::vector > >)'
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
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Fri Oct 29, 2004 7:54 pm Post subject: Re: templated function with vector |
|
|
Daniel L Elliott wrote:
| Quote: | I am feeling very confused right now. The following code gives me an
error:
X.h:
template <typename T
ILuint startImage(vector imageData);
^^^^^^ |
| Quote: | X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
^^^^
test.cpp:
vector<vector 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
std::allocator, std::allocator<std::vector > >)'
Am I not using templates correctly? It appears to have the correct
function.
|
It appears you don't.
V
|
|
| Back to top |
|
 |
Daniel L Elliott Guest
|
Posted: Fri Oct 29, 2004 8:04 pm Post subject: Re: templated function with vector |
|
|
On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
| Quote: | 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 imageData);
^^^^^^
X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
^^^^
test.cpp:
vector<vector 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
std::allocator, std::allocator<std::vector > >)'
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 imageData);
X.cpp:
template<typename T>
void X::startImage(vector<vector imageData){blah}
test.cpp:
vector<vector 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
std::allocator,
std::allocator<std::vector > >)'
Thanks anyway.
- dan
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Fri Oct 29, 2004 8:16 pm Post subject: Re: templated function with vector |
|
|
"Daniel L Elliott" <dan_elliott_at_cox_dot_net (AT) spam_is_pathetic (DOT) com> wrote
in message news:pan.2004.10.29.20.04.27.697158 (AT) spam_is_pathetic (DOT) com...
| Quote: | 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 imageData);
^^^^^^
X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
^^^^
test.cpp:
vector<vector 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
std::allocator,
std::allocator<std::vector > >)'
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 imageData);
X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
test.cpp:
vector<vector 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
std::allocator,
std::allocator<std::vector > >)'
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
|
|
| Back to top |
|
 |
Daniel L Elliott Guest
|
Posted: Fri Oct 29, 2004 8:45 pm Post subject: Re: templated function with vector |
|
|
On Fri, 29 Oct 2004 21:16:48 +0100, John Harrison wrote:
| Quote: |
"Daniel L Elliott" <dan_elliott_at_cox_dot_net (AT) spam_is_pathetic (DOT) com> wrote
in message news:pan.2004.10.29.20.04.27.697158 (AT) spam_is_pathetic (DOT) 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 imageData);
^^^^^^
X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
^^^^
test.cpp:
vector<vector 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
std::allocator,
std::allocator<std::vector > >)'
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 imageData);
X.cpp:
template<typename T
void X::startImage(vector imageData){blah}
test.cpp:
vector<vector 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
std::allocator,
std::allocator<std::vector > >)'
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
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Fri Oct 29, 2004 8:46 pm Post subject: Re: templated function with vector |
|
|
| Quote: |
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-lite/containers-and-templates.html
john
|
|
| Back to top |
|
 |
Default User Guest
|
Posted: Fri Oct 29, 2004 8:52 pm Post subject: Re: templated function with vector |
|
|
Daniel L Elliott wrote:
| Quote: | 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-lite/containers-and-templates.html#faq-34.12
Brian
|
|
| Back to top |
|
 |
Daniel L Elliott Guest
|
Posted: Sat Oct 30, 2004 12:16 am Post subject: Re: templated function with vector |
|
|
On Fri, 29 Oct 2004 13:52:20 -0700, Default User wrote:
| Quote: |
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-lite/containers-and-templates.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
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Sat Oct 30, 2004 1:51 am Post subject: Re: templated function with vector |
|
|
"Daniel L Elliott" <dan_elliott_at_cox_dot_net (AT) spam_is_pathetic (DOT) com>
wrote...
| Quote: | [..]
http://www.parashift.com/c++-faq-lite/containers-and-templates.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
|
|
| 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
|
|