473,405 Members | 2,262 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,405 software developers and data experts.

templates c++

Hello everyone. Normally I would search the entire internet to find a
solution, but this time I've got a situation. I've been trying to solve
this myself for a couple of days. Please help.

=============================================
Errors:
=============================================
In instantiation of `lista_iter<char*>':
lista_iter.cpp:22: instantiated from here
lista_iter.cpp:13: template-id
`operator+<>' for `lista_iter<char*> operator+(const lista_iter<char*>&,
const lista_iter<char*>&)' does not match any template declaration
lista_iter.cpp:12: template-id
`operator<< <>' for `std::basic_ostream<char, std::char_traits<char> >&
operator<<(std::basic_ostream<char, std::char_traits<char> >&, const
lista_iter<char*>&)' does not match any template declaration
=============================================
Program:
=============================================

#include <iostream>

using namespace std;

template <class T>
class lista_iter{
protected:
int wezel_;
public:
lista_iter() : wezel_(0) { };
int szukaj(T, int);
friend ostream& operator<< <> (ostream&, const lista_iter<T> &);
friend lista_iter<T> operator+ <> (const lista_iter<T> &, const
lista_iter<T> &);
};

template <class T>
int lista_iter<T>::szukaj(T a, int b){
return 0;
}

template <>
int lista_iter<char*>::szukaj(char* a, int b){
return 1;
}

template <class T>
ostream& operator<<(ostream& strumien, const lista_iter<T>& lista){
return strumien;
}

template <>
ostream& operator<<(ostream& strumien, const lista_iter<char*>& lista){
return strumien;
}

template <class T>
lista_iter<T> operator+(const lista_iter<T> & a, const lista_iter<T> & b){
return a;
}

int main(){
lista_iter<int> a;
lista_iter<char*> b;
return 0;
}

--
Wodny
Marcin Szewczyk
http://www.wodny.prv.pl
wodny@21%_w_atmosferze.pl
GG:4624915
Jul 23 '05 #1
5 1666
Marcin Szewczyk (Wodny) wrote:
Hello everyone. Normally I would search the entire internet to find a
solution, but this time I've got a situation. I've been trying to solve
this myself for a couple of days. Please help.
[...]


The code as posted compiles fine with Visual C++ .NET 2003 and with
Comeau online test-drive compiler. Perhaps you need to update the
compiler you've been using...

V
Jul 23 '05 #2
Victor Bazarov wrote:
Marcin Szewczyk (Wodny) wrote:
Hello everyone. Normally I would search the entire internet to find a
solution, but this time I've got a situation. I've been trying to
solve this myself for a couple of days. Please help.
[...]

The code as posted compiles fine with Visual C++ .NET 2003 and with
Comeau online test-drive compiler. Perhaps you need to update the
compiler you've been using...


OK. Thanks. But still it has to compile at school, where g++ is used.

--
Wodny
Marcin Szewczyk
http://www.wodny.prv.pl
wodny@21%_w_atmosferze.pl
GG:4624915
Jul 23 '05 #3
Marcin Szewczyk (Wodny) wrote:
Victor Bazarov wrote:
Marcin Szewczyk (Wodny) wrote:
Hello everyone. Normally I would search the entire internet to find a
solution, but this time I've got a situation. I've been trying to
solve this myself for a couple of days. Please help.
[...]


The code as posted compiles fine with Visual C++ .NET 2003 and with
Comeau online test-drive compiler. Perhaps you need to update the
compiler you've been using...

OK. Thanks. But still it has to compile at school, where g++ is used.


Our school used to have really crappy chalk (different country, different
epoch). Teachers and students struggled with it to the point when nobody
couldn't read nothing off the friggin' blackboard. So I brought my own
chalk (let's not go into where I got it). Our lessons went smoother and
when pieces of the chalk I brought remained after our lessons, others
benefited too. True story.

V
Jul 23 '05 #4
Marcin Szewczyk (Wodny) wrote:
Hello everyone. Normally I would search the entire internet to find a
solution, but this time I've got a situation. I've been trying to solve
this myself for a couple of days. Please help.

=============================================
Errors:
=============================================
In instantiation of `lista_iter<char*>':
lista_iter.cpp:22: instantiated from here
lista_iter.cpp:13: template-id
`operator+<>' for `lista_iter<char*> operator+(const lista_iter<char*>&,
const lista_iter<char*>&)' does not match any template declaration
lista_iter.cpp:12: template-id
`operator<< <>' for `std::basic_ostream<char, std::char_traits<char> >&
operator<<(std::basic_ostream<char, std::char_traits<char> >&, const
lista_iter<char*>&)' does not match any template declaration
=============================================
Program:
=============================================

#include <iostream>

using namespace std;

template <class T>
class lista_iter{
protected:
int wezel_;
public:
lista_iter() : wezel_(0) { };
int szukaj(T, int);
friend ostream& operator<< <> (ostream&, const lista_iter<T> &);
friend lista_iter<T> operator+ <> (const lista_iter<T> &, const
lista_iter<T> &);
};

template <class T>
int lista_iter<T>::szukaj(T a, int b){
return 0;
}

Move the following specialization so that it appears after
all of the operator<< and operator+ templates have been defined
(i.e. move it just before main()). The compiler is trying to
instantiate a lista_iter<char*>, but the compiler has not yet
read the code for all of the required operators because they
appear later in the source file.
template <>
int lista_iter<char*>::szukaj(char* a, int b){
return 1;
}

template <class T>
ostream& operator<<(ostream& strumien, const lista_iter<T>& lista){
return strumien;
}

template <>
ostream& operator<<(ostream& strumien, const lista_iter<char*>& lista){
return strumien;
}

template <class T>
lista_iter<T> operator+(const lista_iter<T> & a, const lista_iter<T> & b){
return a;
}

int main(){
lista_iter<int> a;
lista_iter<char*> b;
return 0;
}


Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #5
Larry I Smith wrote:
Marcin Szewczyk (Wodny) wrote:
=============================================
Errors:
=============================================
In instantiation of `lista_iter<char*>':
lista_iter.cpp:22: instantiated from here
lista_iter.cpp:13: template-id
`operator+<>' for `lista_iter<char*> operator+(const lista_iter<char*>&,
const lista_iter<char*>&)' does not match any template declaration
lista_iter.cpp:12: template-id
`operator<< <>' for `std::basic_ostream<char, std::char_traits<char> >&
operator<<(std::basic_ostream<char, std::char_traits<char> >&, const
lista_iter<char*>&)' does not match any template declaration
=============================================
Program:
=============================================

#include <iostream>

using namespace std;

template <class T>
class lista_iter{
protected:
int wezel_;
public:
lista_iter() : wezel_(0) { };
int szukaj(T, int);
friend ostream& operator<< <> (ostream&, const lista_iter<T> &);
friend lista_iter<T> operator+ <> (const lista_iter<T> &, const
lista_iter<T> &);
};

template <class T>
int lista_iter<T>::szukaj(T a, int b){
return 0;
}

Move the following specialization so that it appears after
all of the operator<< and operator+ templates have been defined
(i.e. move it just before main()). The compiler is trying to
instantiate a lista_iter<char*>, but the compiler has not yet
read the code for all of the required operators because they
appear later in the source file.


Thank You very much. Why is it so simple :-) ?!

--
Wodny
Marcin Szewczyk
http://www.wodny.prv.pl
wodny@21%_w_atmosferze.pl
GG:4624915
Jul 23 '05 #6

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

Similar topics

1
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
12
by: Fabio De Francesco | last post by:
Hello. I can't understand why I can't compile the following simple code, where I think I have applied all the needed rules for templates that are declared and defined in different files (*.h and...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
2
by: jimbo_vr5 | last post by:
Hey I think i've figured out the idea behind apply-templates. But going through the tutorial on <http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply just something that i dont...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
7
by: Chris | last post by:
Hi All, This is a weird one but I am hoping someone can help or has some pointers, a recipe how to do the following: I have to move some code from c++ to objective-c and to do this I must...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.