stl模板库成员函数重载类型混肴编译不通过解决方法

stl模板库成员函数重载类型混肴编译不通过解决方法
这种方式编译不通过IsArithmetic和HasMemberList编译器存在混肴

template ::value>::type >
		static void DumpWrapper(T* filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			enum : std::size_t { IntValSize = sizeof(T) };
			if (IntValSize > 4)
			{
				printf("%s:=>%016llx\r\n", fieldname.c_str(), *filed);
			}
			else
			{
				printf("%s:=>%08x\r\n", fieldname.c_str(), *filed);
			}
		}
		template ::value >::type  >
		static void DumpWrapper(T filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			enum : std::size_t { IntValSize = sizeof(T) };
			if (IntValSize > 4)
			{
				printf("%s:=>%016llx\r\n", fieldname.c_str(), filed);
			}
			else
			{
				printf("%s:=>%08x\r\n", fieldname.c_str(), filed);
			}
		}


		template >
		static void DumpWrapper(nop::S7PlusPacketValue* filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			filed.Dump();

		}
		template >
		static void DumpWrapper(nop::S7PlusPacketValue filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			filed->Dump();

		}

解决方法必须明确重载IsArithmetic和HasMemberList编译器存在混肴,加上双重判断typename Enable = std::enable_if::type来明确混肴条件,这种方式编译通过


		template ::value&!HasMemberList::value>::type >
		static void DumpWrapper(T* filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			enum : std::size_t { IntValSize = sizeof(T) };
			if (IntValSize > 4)
			{
				printf("%s:=>%016llx\r\n", fieldname.c_str(), *filed);
			}
			else
			{
				printf("%s:=>%08x\r\n", fieldname.c_str(), *filed);
			}
		}
		template ::value & !HasMemberList::value>::type  >
		static void DumpWrapper(T filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			enum : std::size_t { IntValSize = sizeof(T) };
			if (IntValSize > 4)
			{
				printf("%s:=>%016llx\r\n", fieldname.c_str(), filed);
			}
			else
			{
				printf("%s:=>%08x\r\n", fieldname.c_str(), filed);
			}
		}


		template >
		static void DumpWrapper(nop::S7PlusPacketValue* filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			filed.Dump();

		}
		template >
		static void DumpWrapper(nop::S7PlusPacketValue filed, std::string fieldname)
		{
			printf("fieldname:=>%s\r\n", fieldname.c_str());
			filed->Dump();

		}

你可能感兴趣的:(windows,c++,开发语言)