G
Grizlyk
I found, that I must write explicit cast from non-const reference to const
reference.
I have a class with member returning non-const reference to itself
template<class A,class B,class C>
class X
{
public:
X& my_member(){return *this;}
};
And I have a class working with const reference on X<>
template<class A,class B,class C>
class Y
{
public:
typedef X<A,B,C> X;
void work(const X&, const X&);
};
And I have a class with typedefs
template<class A,class B,class C>
class Z
{
public:
typedef X<A,B,C> X;
typedef Y<A,B,C> Y;
};
When i try to use the classes together
{
Z::X x1,x2;
Z::Y y;
//error - does not match y.work
y.work( x1.my_member(), x2.my_member() );
//ok
y.work(
static_cast<const Z::X&>(x1.my_member()),
static_cast<const Z::X&>(x2.my_member())
);
//ok
y.work( x1, x2 );
}
Why "error - does not match y.work"?
reference.
I have a class with member returning non-const reference to itself
template<class A,class B,class C>
class X
{
public:
X& my_member(){return *this;}
};
And I have a class working with const reference on X<>
template<class A,class B,class C>
class Y
{
public:
typedef X<A,B,C> X;
void work(const X&, const X&);
};
And I have a class with typedefs
template<class A,class B,class C>
class Z
{
public:
typedef X<A,B,C> X;
typedef Y<A,B,C> Y;
};
When i try to use the classes together
{
Z::X x1,x2;
Z::Y y;
//error - does not match y.work
y.work( x1.my_member(), x2.my_member() );
//ok
y.work(
static_cast<const Z::X&>(x1.my_member()),
static_cast<const Z::X&>(x2.my_member())
);
//ok
y.work( x1, x2 );
}
Why "error - does not match y.work"?