我在创建QVariant自定义类型时遇到问题.这是一个小例子,展示了我想要实现的目标:
main.cpp中:
#include "MyClass.h"
int main() {
MyClass some_object;
QVariant variant(some_object);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
包括/ MyClass.h:
#pragma once
#include <QtCore>
class MyClass {
public:
MyClass() : _my_member(0.0) {}
MyClass(const MyClass &other) { _my_member = other._my_member; }
~MyClass() {}
MyClass& operator=(MyClass& other)
{
swap(*this, other);
return *this;
}
MyClass(MyClass&& other) : MyClass()
{
swap(*this, other);
}
friend void swap(MyClass& first, MyClass& second)
{
using std::swap;
swap(first._my_member, second._my_member);
}
private:
float _my_member;
};
Q_DECLARE_METATYPE(MyClass);
Run Code Online (Sandbox Code Playgroud)
构建失败,并出现以下错误:
error: no matching function for …Run Code Online (Sandbox Code Playgroud) 我有一个功能appendLetters :: [[Char]] -> [[Char]].当我尝试iterate像这样调用这个函数时:iterate appendLetters [""],ghci告诉我:
Couldn't match type '[Char]' with 'Char'
Expected type: [Char] -> [Char]
Actual type: [[Char]] -> [[Char]]
In the first argument of 'iterate', namely 'appendLetters'
In the second argument of 'genericTake', namely
'(iterate appendLetters [""])'
In the expression: genericTake n (iterate appendLetters [""])
Couldn't match expected type 'Char' with actual type `[Char]'
In the expression: ""
In the second argument of 'iterate', namely '[""]'
In the second argument …Run Code Online (Sandbox Code Playgroud)