One thing that MSVC ++ allows you to do is explicitly specialize templates within a class. For example.
class X { public: template <typename T> void doStuff(T value); template <> void doStuff<bool>(bool value) {
This compiles in VS, but trying to compile in GCC will give an error telling you that you have an explicit specialization in the field of namespace. The solution for this is to simply drag and drop the specialization.
class X { public: template <typename T> void doStuff(T value); }; template <> void X::doStuff<bool>(bool value) {
GCC is correct on this issue, although according to the specification, which states that all explicit specializations must be in the namespace area.
It may be worth noting that in the latter case, you should define your specialization in the header file, not the implementation file, as you usually expect. Both of the compilers mentioned do not comply with the standard that would solve this problem, namely the export keyword specified in the specialization in the implementation file. However, this function is not implemented by most compilers, and there are plans to remove it from the next version of the specification.
Mark h
source share