NoAvailableAlias / nano-signal-slot

Pure C++17 Signals and Slots
MIT License
407 stars 60 forks source link

Compilation error on MSVC 16.4.2 #26

Closed RT2Code closed 4 years ago

RT2Code commented 4 years ago

Hello,

When trying to build a project using nano-signal-slot, I get the following error :

Error C7510 'static_pointer_cast': use of dependent template name must be prefixed with 'template'

From this line in nano_observer.hpp : line 111: MT_Policy::static_pointer_cast<Observer>(observer)->remove(slot.delegate);

I'm using Visual studio 2019 version 16.4.2 with C++17 and conformant mode enabled.

If I try to fix this error by adding the template keyword like this : line 111: MT_Policy::template static_pointer_cast<Observer>(observer)->remove(slot.delegate);

Then I get the following error : Error C2243 'static_cast': conversion from 'Nano::ST_Policy::Weak_Ptr' to 'T *' exists, but is inaccessible

Which can be fixed by changing the inheritance mode of MT_Policy to public (though it's probably not the best way to fix it) : line 13: class Observer : public MT_Policy

NoAvailableAlias commented 4 years ago

Thanks for reporting this issue, I'll take a look after work today. I was sure permissive- was being used already.

RT2Code commented 4 years ago

I just tried with permissive+, and I'm having the same error. Maybe it is related to a newer version of MSVC?

NoAvailableAlias commented 4 years ago

I was previously using 16.4.0 and now with permissive- I am encountering this issue. However, I'm not sure why it complains about accessibility with protected policy inheritance. Public inheritance isn't desirable and defeats the encapsulation that the policy system provided.

Naturally reinterpret_cast allows even private policy inheritance and might be the solution if it can be proven safe.

Fix will be soon, the static cast must be made in Observer and not in the policy.

RT2Code commented 4 years ago

Awesome, thanks for the very quick fix. I just tried your library again, and the performances are top-notch, very nice work.

NoAvailableAlias commented 4 years ago

No problem, glad you like the library, and thanks again for reporting the issue. I have published the 2.0.1 release.