Thank you for helping and here is the problem:

#include <string>
#include <fstream>
#include <vector>
#include <iostream>
using std::string;
using std::ifstream;
template<class t>
class Openfile
	string pavadinimas;
	ifstream fin;
	typedef ifstream & reference; 
	Openfile(const char * c);
	reference rout();
	std::vector<t> & operator>>(std::vector<t> &);

I 'm getting problem when I trying to define the ruot() function and here is the definition:

template<class t>
Openfile<t>::reference Openfile<t>::rout()
	return fin;

When I change the t to string type argument th problem goes away.
My compiler say the I' am missing destructor, constructor before Openfile...

Edited by cppgangster: n/a

7 Years
Discussion Span
Last Post by StuXYZ

It is another one of these typename instances.

First off the solution is this:

template<class t>
typename Openfile<t>::reference Openfile<t>::rout()
  return fin;

Ok that is the simple part, now I am going to make a complete mess of trying to explain WHY you need a typename. [sorry in advance].

The compile at this point when it sees somthing like this:

template<typename T> 
A<T>::X A<T>::Y() { }

Now what does that mean? It could be a method definition as you wish it to be OR it could be a constructor e.g. a complex form of

template<typename T>
class A 
   class X {};

A<T>::X object();

Now to avoid this ambiguity, you have to add typename. Note EVEN if you have the whole class there in the definition, this still holds. The basic rule is if you are using a template in a object type that is NOT a instance declaration then you need a typename.

Edited by StuXYZ: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.