Re: Cannot compile with templated classes
On Oct 9, 8:09 am, sam.bark...@gmail.com wrote:
I have this following error
In test.h
=========================
===================
#include <iostream>
#include <cstddef>
#include <utility>
template<typename T> class myclass;
template<typename T> std::ostream& operator<< (std::ostream&, const
myclass<T>&);
template <typename T> class myclass {
public:
friend std::ostream& operator<< <T> (std::ostream& os, const
myclass<T>& var1);
...
..
..
private:
struct mysubclass
{
int par1;
int par2;
};
};
#include "myclass.tem"
=========================
=====================
In myclass.tem,I have
=========================
=======================
#include <cassert>
#include <algorithm>
template<typename T>
std::ostream& operator<< (std::ostream& values, const myclass<T>&
var1)
{
typename myclass<T>::mysubclass *current;
current->par1=89;
.................................
....................................
}
When I compile I get the error
In myclass.tem
error: ?par1? was not declared in this scope
What am I doing wrong.How can solve this.
What complier are you using? What is the exact error message?
And the exact code which triggers it?
Deleting the "..." lines in your code and adding a return to the
operator<<, it compiles with all of the compilers available to
me (Sun CC, g++ and VC++), including if add code to instantiate
the function.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34