Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译器错误";collect2:Id返回1退出状态“;使用带有QObject的类(带有QtCreator的Qt4.7)_C++_Qt_Virtual_Derived_Qobject - Fatal编程技术网

C++ 编译器错误";collect2:Id返回1退出状态“;使用带有QObject的类(带有QtCreator的Qt4.7)

C++ 编译器错误";collect2:Id返回1退出状态“;使用带有QObject的类(带有QtCreator的Qt4.7),c++,qt,virtual,derived,qobject,C++,Qt,Virtual,Derived,Qobject,在我当前的项目中,我遇到了以下情况:“collect2:Id returned 1 exit status”由编译器使用以下代码返回: #ifndef BASE_02_H #define BASE_02_H #include <QtCore> class Base_02 { public: Base_02(); virtual void method()=0; }; #endif // BASE_02_H #include "base_02.h" #inc

在我当前的项目中,我遇到了以下情况:“collect2:Id returned 1 exit status”由编译器使用以下代码返回:

#ifndef BASE_02_H
#define BASE_02_H

#include <QtCore>

class Base_02
{

public:
    Base_02();

    virtual void method()=0;
};

#endif // BASE_02_H

#include "base_02.h"
#include <QtCore>

Base_02::Base_02()
{

}

//----------------------------------------------------------------------------------------------------------------------------------

#ifndef DERIVED_02_H
#define DERIVED_02_H

#include <QtCore>
#include "base_02.h"

class Derived_02 : public Base_02
{

public:
    Derived_02();
    void method();
};

#endif // DERIVED_02_H

#include "derived_02.h"
#include <QtCore>

Derived_02::Derived_02()
{

}

void Derived_02::method()
{
    qDebug() << "Derived_02::method()";
}

//----------------------------------------------------------------------------------------------------------------------------------

#ifndef BASE_H
#define BASE_H

#include <QtCore>

class Base : public QObject
{
    Q_OBJECT

public:
    Base(Base* p=NULL);

    virtual void method()=0;
};

#endif // BASE_H

#include "base.h"
#include <QtCore>

Base::Base(Base* p)
{

}

//----------------------------------------------------------------------------------------------------------------------------------

#ifndef DERIVED_H
#define DERIVED_H

#include <QtCore>
#include "base.h"

class Derived : public Base
{
    Q_OBJECT

public:
    Derived(Derived* p=NULL);
    void method();
};

#endif // DERIVED_H

#include "derived.h"
#include "derived_02.h"
#include <QtCore>

Derived::Derived(Derived* p)
{

}

void Derived::method()
{
    Derived_02 d;
    d.method();
}

//----------------------------------------------------------------------------------------------------------------------------------

#include <QtCore/QCoreApplication>
#include <QtCore>
#include "base.h"
#include "derived.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);



    Derived* derived = new Derived();



    return a.exec();
}
\ifndef BASE\u 02\u H
#定义基本参数
#包括
类基_02
{
公众:
Base_02();
虚空方法()=0;
};
#endif//BASE_02_H
#包括“base_02.h”
#包括
Base_02::Base_02()
{
}
//----------------------------------------------------------------------------------------------------------------------------------
#ifndef导出的\u 02\u H
#定义派生的\u 02\u H
#包括
#包括“base_02.h”
派生类\u 02:公共基\u 02
{
公众:
派生的_02();
void方法();
};
#endif//派生的\u 02\u H
#包括“派生的_02.h”
#包括
派生的_02::派生的_02()
{
}
void派生_02::method()
{
qDebug()
#包括“base_02.h”
#包括
必须是:

#include <QtCore>
#include "base_02.h"
#包括
#包括“base_02.h”

然后编译!

我在以下情况下遇到了这个问题:


A是一个可执行(f.i.控制台)项目,并且 B和C是库(f.i.静态库)项目和 A使用B,B使用C

然后

A必须通过.pro文件了解B库和C库,并且 B必须通过.pro文件了解C库


在.pro文件中,库C在库B之前表示:

LIBS *= -L"../C/debug"
LIBS *= -lC
INCLUDEPATH *= "../C"

LIBS *= -L"../B/debug"
LIBS *= -lB
INCLUDEPATH *= "../B"
然后

准确地说,上述错误是正确的


解决方案:

在.pro文件中将库B命名为库C之前的库:

LIBS *= -L"../B/debug"
LIBS *= -lB
INCLUDEPATH *= "../B"

LIBS *= -L"../C/debug"
LIBS *= -lC
INCLUDEPATH *= "../C"
我这里也有同样的问题。。。??
#包括
使用名称空间std;
班级员工{
受保护的:
int-id;
字符串名;
国际日;
国际工资;
公众:
虚空calsalary()=0;
};
班主任:公职人员{
公众:
静态int k;
facultyemp(){
k++;
id=k;
}
void setname(){
coutname;
}
void setday(){
coutday;
}
void setsalary(){
库塔拉里;
}
void getname(){

像derived.cpp和derived_02.cpp这样的coutlook不会被合并。你是使用QtCreator还是在命令行上运行它?你的makefile是什么?解释为什么这是问题的答案。
LIBS *= -L"../B/debug"
LIBS *= -lB
INCLUDEPATH *= "../B"

LIBS *= -L"../C/debug"
LIBS *= -lC
INCLUDEPATH *= "../C"
I got same problem here...??
#include<iostream>
using namespace std;
class employee{
    protected:
        int id; 
        string name;
        int day;
        int salary;
    public:
        virtual void calsalary()=0;
};
class facultyemp:public employee{
    public:
        static int k;
        facultyemp(){
            k++;
            id=k;
        }
        void setname(){
            cout<<"Enter name:";
            cin>>name;
        }
        void setday(){
            cout<<"Enter worked days:";
            cin>>day;
        }
        void setsalary(){
            cout<<"Enter salary pr day:";
            cin>>salary;
        }
        void getname(){
            cout<<"Name: "<<name;
        }
        void getid(){
            cout<<"\nID: "<<id;
        }
        void calsalary(){
            cout<<"The net salary: ";
            cout<<day*salary;
        }

};
static int k=0;
int main(){
    employee *e;
    facultyemp f;
    e=&f;
    f.setname();
    f.setday();
    f.setsalary();
    f.getname();
    f.getid();
    e->calsalary();

}