小编Luc*_*984的帖子

使用QVector时,没有匹配的默认构造函数调用

我有一个B类,它创建一个A类的对象并调用该对象的方法.

#ifndef A_H
#define A_H

class A
{
public:
    A(int);
    void function();
};

#endif // A_H
Run Code Online (Sandbox Code Playgroud)

a.cpp

#include "a.h"

A::A(int x)
{

}
void A::function(){
    //Do something.
}
Run Code Online (Sandbox Code Playgroud)

BH

#ifndef B_H
#define B_H
#include <QVector>
#include <a.h>


class B
{
public:
    B(int);
    QVector<A> list;
};

#endif // B_H
Run Code Online (Sandbox Code Playgroud)

b.cpp

#include "b.h"

B::B(int y)
{
    list.append(A(y));
    list[0].function();
}  
Run Code Online (Sandbox Code Playgroud)

问题是这不能编译.它返回"没有匹配的函数来调用'A:A()'".我知道这可以通过前向声明来解决,但这在这里不起作用,因为我想调用函数"function".我也不想把全班A都包括在B班.

c++ qt qvector

3
推荐指数
1
解决办法
205
查看次数

访问数据类型的属性

我创建了一个新的数据类型:

data Human = Human [Names] Age
  deriving(Eq,Show)
type Names = String
type Age = Int
Run Code Online (Sandbox Code Playgroud)

现在我想访问Human类型对象的[Names]元素:

human1 = Human ["FirstName","LastName"] 22
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法可以为我的例子做这个Names human1吗?

haskell

0
推荐指数
1
解决办法
62
查看次数

标签 统计

c++ ×1

haskell ×1

qt ×1

qvector ×1