Assignment issues

After the last problem, I encountered another.
Continuing on the shared pointer, I cannot assign the right-hand side m_ptr to the left-hand side because it's a templated-type pointer (see code).
So, I wrapped the pointer in a struct, yet I still cannot seem to get it right. I was hoping anyone with some good eyes or some free time could help me with it.

1) The code for 'sptr' in your example is incomplete
2) How exactly does class 'Derived' tie into 'mad_shared_ptr'?
3) 'mad_shared_ptr' has no assignment operator for a pointer to 'T'.
4) The purpose of 'sptr_wrapper' is unclear. Can you explain that? Further, where is it supposed to get a pointer to an 'sptr', anyway?
5) Template functions expecting another type of 'mad_shared_ptr' should forward *all* of the template parameters - not just the first one.
6) Your back to the same problem you had earlier, this time with 'sptr_wrapper' (only now in a more complicated context). Namely, a mad_shared_ptr<T, thread_safety, Bits>::sptr_wrapper<T2, Bits2> with different parameters will, of course, yield a completely different type, so the protected qualifier prevents access.
7) The idea of assigning, say, a mad_shared_ptr< float > to a mad_shared_ptr< string > doesn't even really make sense. How is that supposed to work?

Lot's of confusing issues, IMO. Maybe you could describe more clearly what you're wanting to do?

1) The code for 'sptr' in your example is incomplete
3) 'mad_shared_ptr' has no assignment operator for a pointer to 'T'.

Because this is a minimal code example. The real code does not have these issues.

2) How exactly does class 'Derived' tie into 'mad_shared_ptr'?

Because it's a test to get it working right. Will remove when it works fine.

4) The purpose of 'sptr_wrapper' is unclear. Can you explain that? Further, where is it supposed to get a pointer to an 'sptr', anyway?

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.

5) Template functions expecting another type of 'mad_shared_ptr' should forward *all* of the template parameters - not just the first one.

Not 100% sure what you mean.

6) Your back to the same problem you had earlier, this time with 'sptr_wrapper' (only now in a more complicated context). Namely, a mad_shared_ptr<T, thread_safety, Bits>::sptr_wrapper<T2, Bits2> with different parameters will, of course, yield a completely different type, so the protected qualifier prevents access.

Yes, but we solved that with friends earlier, didn't we? Yes, we did.

7) The idea of assigning, say, a mad_shared_ptr< float > to a mad_shared_ptr< string > doesn't even really make sense. How is that supposed to work?

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.

Lot's of confusing issues, IMO. Maybe you could describe more clearly what you're wanting to do?

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.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

Because this is a minimal code example. The real code does not have these issues.

Okay, I see.

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.

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.

Invoking 'bar' forces the compiler to forward the default template parameters, so it fails to compile.

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.

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?

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.

I took the liberty of trying another approach.
I still get the pesky access errors, however. Don't know if it will yield more errors beyond what I get and if any linker errors.
Anyway, I did promise the code so you could see what's going on, so here it is: