Connecting Tech Pros Worldwide Forums | Help | Site Map

how to declare/define a simple template.

Javi
Guest
 
Posts: n/a
#1: Oct 11 '05
Hi!. I just need for the sake of comfortability a function to write to
the standar output the contents of a list, but I'm doing something
wrong:

______
myfile.h
#include <list>

namespace myspace{
template<class C> void displaylist(list<C>&);
}
______
myfile.cpp
#include <list>

template<class C> myspace::displaylist(list<C>& L){...}
_____
main.cpp
#include <list>
#include "myfile.h"

int main(){
list<int> L;
..... // fill L with some ints
myspace::displaylist(L);
}
________

When I compile this scheme I obtain this error:

"undefined reference to: void myspace::displaylist<int>(std::list<int,
std::allocator<int> >&)"


Can you please tell me what's wrong?.

Thanks in advance,

javi.


Victor Bazarov
Guest
 
Posts: n/a
#2: Oct 11 '05

re: how to declare/define a simple template.


Javi wrote:[color=blue]
> Hi!. I just need for the sake of comfortability a function to write to
> the standar output the contents of a list, but I'm doing something
> wrong:
>
> ______
> [...]
> ________
>
> When I compile this scheme I obtain this error:
>
> "undefined reference to: void myspace::displaylist<int>(std::list<int,
> std::allocator<int> >&)"
>
>
> Can you please tell me what's wrong?.[/color]

Simple. You're not reading the FAQ before posting.

V
Javi
Guest
 
Posts: n/a
#3: Oct 11 '05

re: how to declare/define a simple template.


Yes, sure, I've not read any FAQS at all (now, I mean). Which one are
you refering to?. A c++ FAQ or maybe there's something wrong with my
post?.

I would appreciate any help with this simple problem but if you
forward me to any other kind of documentation it will be welcome too.

Thank you,
Javi

Victor Bazarov
Guest
 
Posts: n/a
#4: Oct 11 '05

re: how to declare/define a simple template.


Javi wrote:[color=blue]
> Yes, sure, I've not read any FAQS at all (now, I mean). Which one are
> you refering to?. A c++ FAQ or maybe there's something wrong with my
> post?.[/color]

I don't know how to tell you... If you read the C++ FAQ Lite (you can
find it here: http://www.parashift.com/c++-faq-lite/), you wouldn't need
to post at all. Now, does that mean there's something wrong with your
post?

If you need further guidance, it's section 35 that you need in the FAQ.

V
Javi
Guest
 
Posts: n/a
#5: Oct 11 '05

re: how to declare/define a simple template.


Thank you, I didn't know that FAQ and looks quite good.

I've not managed yet to solve the problem but I hope I will.

Thank you again,
Javi.

Closed Thread