Connecting Tech Pros Worldwide Help | Site Map

how to declare/define a simple template.

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 11th, 2005, 02:25 PM
Javi
Guest
 
Posts: n/a
Default how to declare/define a simple template.

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, 02:35 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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, 02:45 PM
Javi
Guest
 
Posts: n/a
Default 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, 03:05 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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, 03:35 PM
Javi
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.