在赋值时不能将'int *'转换为'ABC *'

时间:2014-09-02 16:06:10

标签: c++ compiler-errors

我无法弄清楚这个小编译错误......

file.h

    #ifndef FILE_H
    #define FILE_H

    class ABC: public QWidget
    {
        Q_OBJECT

    public:
        ABC(QWidget* parent) : QWidget(parent)
        {       
    ..
        }
    ..
    };

    class BCD : public QDialog
    {
    ....

        ABC* m_abc;
    };
#endif

在file.cpp

#include "file.h"
BCD::BCD()
{
  ....
    m_abc = new ABC::ABC(ui->frame);   /// line with errors
}

得到错误

expected type specifier
cannot convert 'int*' to 'ABC*' in assignment
expected ;

所以我尝试研究找出这个错误的原因......并检查可能的问题......(比如这个问题Error: expected type-specifier before 'ClassName'

我的包含警卫很好,课程设置正常,智能感知找到所有符号......

将行更改为

m_abc = new ::ABC::ABC(ui->frame); 

会导致错误:

expected type specifier before :: token
cannot convert 'int*' to 'ABC*' in assignment
expected ; before '::' token

我在哪里可以找到我的错误?

抱歉,我无法列出整个代码。

1 个答案:

答案 0 :(得分:3)

new ABC::ABC(ui->frame)应为new ABC(ui->frame)

你正在调用构造函数错误。

原因是ABC :: ABC在命名空间ABC(你可能没有,因此它默认为int)中查找ABC类,但如果你只使用ABC,它将在当前命名空间中找到ABC

相关问题