VC特殊符号和定义

时间:2022-07-22
本文章向大家介绍VC特殊符号和定义,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

对像只能在堆上

析构函数设为私有,只能new和delete

private :  
    ~A(){}  

对象只能在栈上

重载符号为私有

private :  
    void * operator  new ( size_t  t){}      // 注意函数的第一个参数和返回值都是固定的   
    void  operator  delete ( void * ptr){}  // 重载了new就需要重载delete   

参考:https://www.cnblogs.com/vincently/p/4838283.html

宏定义特殊符号

定义在宏中才能编译通过

  • #字符串转换,如转换类名#classname
  • #@字符转换,输入超过4个字符报错,可以使用转换acsii
  • ##合成新的符号,如class##A

模板类型限定

函数模板

template<typename T>
typename std::enable_if < std::is_same<glm::dvec3, T>::value || std::is_same<glm::dvec2, T>::value, void >::type

类模板

  • 类型断言
static_assert( sizeof(int) == sizeof(T) || sizeof(float) == sizeof(T),"T type is not the specified DataType including int and float");
  • 模板嵌套使用