My question is how can I solve the following error:
In this case you have two different projects in QT. One of them contains a class called "Numbers".
File .h:
#ifndef NUMEROS_H
#define NUMEROS_H
class Numeros
{
public:
Numeros(int a, int b);
Numeros();
int suma();
private:
int m_a, m_b;
};
#endif // NUMEROS_H
.cpp file:
#include "numeros.h"
Numeros::Numeros(int a, int b):
m_a(a), m_b(b)
{
}
Numeros::Numeros()
{
m_a = 2;
m_b = 3;
}
int Numeros::suma(){
return m_a+m_b;
}
You want to use the "Numbers" class of the first project in the other project. For this, the route of Project 1 is included in the .pro file of Project 2 and the following code is written in the "main":
#include <iostream>
#include <numeros.h>
int main()
{
Numeros *s2;
s2 = new Numeros();
return 0;
}
When executing this program, the following error occurs:
main.obj: -1: error: LNK2019: unresolved external symbol "public: __cdecl Numbers :: Numbers (void)" (?? 0Numeros @@ QEAA @ XZ) referenced in function main
debug \ Proof2.exe: -1: error: LNK1120: 1 unresolved externals
How could it be solved? Thanks