S
SpOiLeR
Hello everybody...
Following code doesn't work:
class char_convertible
{
public:
char_convertible () : el('t') {}
char_convertible (char arg) : el(arg) {}
operator char () const { return el; }
private:
char el;
};
template <class tclass, typename tname>
class simple_template
{
public:
simple_template (tname arg) : el (arg) {}
virtual ~simple_template() {};
operator tclass() const {return el;}
protected:
tclass el;
};
class simple_inherited : public simple_template<char_convertible,char>
{
public:
simple_inherited (char arg) :
simple_template<char_convertible,char> (arg) {}
operator char_convertible () const { return el; }
};
int main (void)
{
simple_inherited inh ('z');
char chr;
g = t; // Problem line
return 1;
}
In main, compiler complains about line
g = t;
saying "t" is not convertible to char. Why is that? There is operator in
simple_inherited that allows conversion into char_convertible, which is on
the other hand convertible into char. So, it seems it should work. And,
yes, I know that it will work if I add
operator char () const;
into interface of either simple_template or simple_inherited...
TIA...
Following code doesn't work:
class char_convertible
{
public:
char_convertible () : el('t') {}
char_convertible (char arg) : el(arg) {}
operator char () const { return el; }
private:
char el;
};
template <class tclass, typename tname>
class simple_template
{
public:
simple_template (tname arg) : el (arg) {}
virtual ~simple_template() {};
operator tclass() const {return el;}
protected:
tclass el;
};
class simple_inherited : public simple_template<char_convertible,char>
{
public:
simple_inherited (char arg) :
simple_template<char_convertible,char> (arg) {}
operator char_convertible () const { return el; }
};
int main (void)
{
simple_inherited inh ('z');
char chr;
g = t; // Problem line
return 1;
}
In main, compiler complains about line
g = t;
saying "t" is not convertible to char. Why is that? There is operator in
simple_inherited that allows conversion into char_convertible, which is on
the other hand convertible into char. So, it seems it should work. And,
yes, I know that it will work if I add
operator char () const;
into interface of either simple_template or simple_inherited...
TIA...