Quote:
Because this is a minimal code example. The real code does not have these issues.
Okay, I see.
Quote:
Because it's a test to get it working right. Will remove when it works fine.
Ah, okay. At any rate, it doesn't seem to help the situation any, so it may as well just be removed altogether.
Quote:
Look at sptr. It has two template arguments: T and Bits.
This structure contains the actual reference counting, which is shared among all similar pointers.
Hence, in the assignment operator, I would need to duplicate the pointer address from the rhs to the lhs.
But that's impossible since sptr<Base, 32> != sptr<Derived, 32>.
What do we do then? We need a function that makes it possible to assign the rhs to lhs if and only if it's possible to assign rhs.m_ptr->p to lhs.m_ptr->p (the actual pointee it's encapsulating). This should work if rhs's pointer type is derived from lhs's pointer type.
Creating a global assignment operator is not possible, so I made a wrapper so that I could overload operator = instead.
Hmm, still a bit confused on that one...
Quote:
Not 100% sure what you mean.
Well, for example, consider:
Code:
template < typename A, typename B = int, typename C = int >
struct foo
{ };
template < typename A >
void bar( foo< A > const& )
{ }
int main( void )
{
bar( foo< int, double, double >( ) );
}
Invoking 'bar' forces the compiler to forward the default template parameters, so it fails to compile.
Quote:
Yes, but we solved that with friends earlier, didn't we? Yes, we did.
True, but then you should probably incorporate that into your example, so that we know that it isn't an issue. ;)
Quote:
It does not.
However, the idea is to use the compiler as a tool here.
In the end, it should be assigning a string* to a float* and obviously that won't work.
But if we assign a mad_shared_ptr<Derived> to a mad_shared_ptr<Base>, then in the end we should get an assignment of Derived* to Base*.
This is the idea.
I see. But wouldn't it be sufficient to just ensure that a mad_shared_ptr<Base> is used, since that should accept a pointer to a Derived?
Quote:
Basically, what I need is what I described above.
I need to assign a mad_shared_ptr<Derived> to a mad_shared_ptr<Base>.
I would be happy to post the full code, that you may examine it.
You should be aware that it does rely on boost. Although I could make efforts to reduce that dependancy.
In this case, yes, I think the complete code would be most helpful.