Connecting Tech Pros Worldwide Help | Site Map

how to declare/define a simple template.

  #1  
Old October 11th, 2005, 03:25 PM
Javi
Guest
 
Posts: n/a
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.

  #2  
Old October 11th, 2005, 03:35 PM
Victor Bazarov
Guest
 
Posts: n/a

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
  #3  
Old October 11th, 2005, 03:45 PM
Javi
Guest
 
Posts: n/a

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

  #4  
Old October 11th, 2005, 04:05 PM
Victor Bazarov
Guest
 
Posts: n/a

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
  #5  
Old October 11th, 2005, 04:35 PM
Javi
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding the correct way to define "iostream" class? Luna Moon answers 6 October 23rd, 2008 10:35 PM
Self reference in Template class? nw answers 1 June 27th, 2008 05:47 PM
Template Question Suki answers 10 November 1st, 2005 02:25 PM
Noob to C++, trying to get syntax, etc. Rich Grise answers 8 July 22nd, 2005 07:06 PM