operator << inherited?
-
Hi, I was wondering if the << operator is inherited? I can't get the following to work:
class A
{
public:
A& operator << (double & arg)
{
return *this;
}
};
class B : public A
{
public:
B & operator<<(int & arg)
{
return *this;
}
};
...
B test;
test << 5.0;with the error that no operator that takes double as argument.
-
Hi, I was wondering if the << operator is inherited? I can't get the following to work:
class A
{
public:
A& operator << (double & arg)
{
return *this;
}
};
class B : public A
{
public:
B & operator<<(int & arg)
{
return *this;
}
};
...
B test;
test << 5.0;with the error that no operator that takes double as argument.
Hi, Class 'B' is overloading the operator '<<'. In quick mockup test I managed to get the following to work:
class A { public: A& operator << (double arg) { return *this; } }; class B : public A { public: B& operator << (int arg) { return *this; } using A::operator <<; // Provide both implementations. };
I ran into difficulties when using the reference operator '&' for the two arguments. I hope this is of use! Lea Hayes -
Hi, Class 'B' is overloading the operator '<<'. In quick mockup test I managed to get the following to work:
class A { public: A& operator << (double arg) { return *this; } }; class B : public A { public: B& operator << (int arg) { return *this; } using A::operator <<; // Provide both implementations. };
I ran into difficulties when using the reference operator '&' for the two arguments. I hope this is of use! Lea HayesIt appears that when I remove the reference operator, I don't have to specify "using". It's a shame though as I was hoping to subclass an existing implementation and just add a few of my own << operators to write my own types. Looks like I'll have to try defining the operators outside of the class.
-
It appears that when I remove the reference operator, I don't have to specify "using". It's a shame though as I was hoping to subclass an existing implementation and just add a few of my own << operators to write my own types. Looks like I'll have to try defining the operators outside of the class.