
我有一些模板功能,如
std::vector<T> operator - (const std::vector<T>& data1,const std::vector<T>& data2);std::vector<T> operator * (const std::vector<T>& data1,const std::vector<T>& data2);std::vector<T> operator & (const std::vector<T>& data1,const std::vector<T>& data2);
….等等.除了运算符之外,所有这些函数都具有完全相同的定义,因此我尝试编写这样的宏
#define _BINARY_OP_ON_DATASET (OP_TYPE) template <typename T> \ std::vector<T> operator OP_TYPE (const std::vector<T>& data1,const std::vector<T>& data2)\ {\ std::vector<T> result;\ result.push_back(data1.begin().val OP_TYPE data1.begin().val)/*sample implementation*/\ return result;\ }_BINARY_OP_ON_DATASET (&)_BINARY_OP_ON_DATASET (+) 而且我得到了一堆错误
Error 1 error C2833: 'operator OP_TYPE' is not a recognized operator or typeError 2 error C2988: unrecognizable template declaration/deFinitionError 3 error C2059: Syntax error : 'newline'Error 5 error C2143: Syntax error : missing ';' before '<'Error 6 error C4430: missing type specifIEr - int assumed. Note: C++ does not support default-int
…和更多
任何人都可以看到这个问题是什么?
谢谢你的帮助.
简历
解决方法 宏参数列表前没有空格!#define _BINARY_OP_ON_DATASET(OP_TYPE) ... ^^^总结
以上是内存溢出为你收集整理的c – 模板上的宏全部内容,希望文章能够帮你解决c – 模板上的宏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)