小编won*_*key的帖子

Qt - 没有匹配函数来调用'QVariant :: QVariant(MyClass&)'

我在创建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)

c++ qt c++11

5
推荐指数
2
解决办法
1142
查看次数

Haskell迭代参数类型不匹配,为什么?

我有一个功能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)

haskell loops

2
推荐指数
1
解决办法
154
查看次数

标签 统计

c++ ×1

c++11 ×1

haskell ×1

loops ×1

qt ×1