Connecting Tech Pros Worldwide Help | Site Map

templates c++

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 03:57 AM
Marcin Szewczyk (Wodny)
Guest
 
Posts: n/a
Default 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

  #2  
Old July 23rd, 2005, 03:57 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: templates c++

Marcin Szewczyk (Wodny) wrote:[color=blue]
> 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.
> [...][/color]

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
  #3  
Old July 23rd, 2005, 03:57 AM
Marcin Szewczyk (Wodny)
Guest
 
Posts: n/a
Default Re: templates c++

Victor Bazarov wrote:[color=blue]
> Marcin Szewczyk (Wodny) wrote:
>[color=green]
>> 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.
>> [...][/color]
>
>
> 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...[/color]

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
  #4  
Old July 23rd, 2005, 03:57 AM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: templates c++

Marcin Szewczyk (Wodny) wrote:[color=blue]
> Victor Bazarov wrote:
>[color=green]
>> Marcin Szewczyk (Wodny) wrote:
>>[color=darkred]
>>> 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.
>>> [...][/color]
>>
>>
>>
>> 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...[/color]
>
>
> OK. Thanks. But still it has to compile at school, where g++ is used.[/color]

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
  #5  
Old July 23rd, 2005, 03:58 AM
Larry I Smith
Guest
 
Posts: n/a
Default Re: templates c++

Marcin Szewczyk (Wodny) wrote:[color=blue]
> 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;
> }
>[/color]

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.
[color=blue]
> 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;
> }
>[/color]

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
  #6  
Old July 23rd, 2005, 03:58 AM
Marcin Szewczyk (Wodny)
Guest
 
Posts: n/a
Default Re: templates c++

Larry I Smith wrote:[color=blue]
> Marcin Szewczyk (Wodny) wrote:[color=green]
>>=============================================
>>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;
>>}
>>[/color]
>
>
> 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.[/color]

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

--
Wodny
Marcin Szewczyk
http://www.wodny.prv.pl
wodny@21%_w_atmosferze.pl
GG:4624915
 

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,840 network members.