我创建了一个简单的类来传递给Juce数组的sort方法 http://www.rawmaterialsoftware.com/api/classArray.html#ac1dca4ab2895315dd85e25eaca2fcab1
看起来像这样:
class XComparison
{
public:
static int compareElements (StraightPath first, StraightPath second)
{
return (int) (first.xOrigin - second.xOrigin);
}
};
当我创建一个这样的实例传递给比较器时,这两个工作:
XComparison x;
XComparison x = XComparison();
但是这个给了我一个编译器错误:
XComparison x();
“.compareElements'的左边必须有第74,101,119行的类/结构/联合” http://juce.git.sourceforge.net/git/gitweb.cgi?p=juce/juce;a=blob;f=modules/juce_core/containers/juce_ElementComparator.h;h=f976c40c7741b3df30d10e699c282a3569a49e3c;hb=HEAD#l74
为什么隐式赋值在这里不起作用?
谢谢!
答案 0 :(得分:4)
XComparison x();被解析为x的函数声明,它不带参数并返回XComparison。
答案 1 :(得分:1)
您声明的函数不是表达式,这就是您收到错误的原因。
XComparison x; // default construction, unitialised
XComparison x = XComparison(); // construct x from default constructor
XComparison x(); // all you are doing is declaring a function x that returns XComparison
请参阅此C++ faq