473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Oct 11 '05 #1
4 1304
Javi wrote:
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?.


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

V
Oct 11 '05 #2
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

Oct 11 '05 #3
Javi wrote:
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 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
Oct 11 '05 #4
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.

Oct 11 '05 #5

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

Similar topics

97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
14
by: Carl Ribbegaardh | last post by:
What other c++ constructs can I use instead of #define for executing a couple of functions? Example: #define DO_STUFF doThis(); doThat(); I'd guess that I can either use a template function,...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
1
by: quietbritishjim | last post by:
Hi, I want to do something like this: foo.h: class FooData; typedef MyTemplate<FooData> MyFoo; class Foo2: public MyFoo { // ...
7
by: aaragon | last post by:
Hi everyone, I have a simple question. I'm trying to make a macro in one file so I can use it in main.cpp. The idea is that I the user of my code has simple to type the macro definition to replace...
5
by: probstm | last post by:
I am using a message handler class that implements amongst others: static void message ( std::string aHeader, std::string aMessage, int aTimeout = 0, MessageType aFlag = MSG_Information ); ...
7
by: =?gb2312?B?wfXquw==?= | last post by:
Hi folks, I am running into with such a question when I tried to declare and define a friend template function in a template class, here is the code snippet: #include <iostream> using...
10
by: Tammy | last post by:
Hello all, I am wondering what is the best way to declare a struct to be used in other c and c++ files. Such as for a C API that will be used by others. 1. Declaring the typedef and the...
6
by: puzzlecracker | last post by:
Say we have this structure: Struct Foo{ .... friend ostream& operator << (ostream& s, Foo & m); ..... }; friend ostream& operator << (ostream& s, Foo & m){
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.