-2

I get the ERROR LNK1120: 1 unresolved externals & ERROR LNK2019: unresolved external symbol ! While Compiling

Some threads - I end up while searching - say is something about class definitions and other that is something with the .cpp /.h files

The errors:

ERROR LNK1120: 1 unresolved externals.  

ERROR LNK2019: unresolved external symbol "public: __thiscall bandera_Triang::~bandera_Triang(void)" (??1bandera_Triang@@QAE@XZ) referenced in function _main.

Here is the code:

#include <iostream>
using namespace std;

class bandera_Triang {
private:
    float aSide, bSide, cSide;

public:
    bandera_Triang(){ //Cost. sin Param...
        aSide = 0;
        bSide = 0;
        cSide = 0;
    }
    bandera_Triang(float A, float B, float C){ //Const. con Param...
        aSide = A;
        bSide = B;
        cSide = C;
    }

    //Sets...
    void set_A(float A){ aSide = A; }
    void set_B(float B){ bSide = B; }
    void set_C(float C){ cSide = C; }

    //Gets...
    float get_A(){ return aSide; }
    float get_B(){ return bSide; }
    float get_C(){ return cSide; }

    ~bandera_Triang(); //destructor...



    bool esTriang(){ //Desigualdad Triangular...
        if (aSide < bSide + cSide && bSide < aSide + cSide && cSide < aSide + bSide) {
            return true;
        }
        else
            return false;
    }

    string triangOno(bool esTriang()){ //Print si es o no triangulo...
        if (esTriang() == true){
            return "Es Triangulo.";
        }
        else { return "NO es Triangulo."; }
    }

    string tipoTriang(){
        if (aSide == bSide && bSide == cSide){
            return "El triangulo es Equilatero.";
        }
        else
        if (aSide == bSide || aSide == cSide || bSide == cSide){
            return "El triangulo es Isosceles. ";
        }
        return "El triangulo es Escaleno.";
    }

    float arTriang(float aSide, float bSide, float cSide){ //Area Triangulo con F.Heron.

        float lado_A, lado_B, lado_C, SemiPerim, areaTriang; //Variables locales para calculo.

        SemiPerim = (lado_A + lado_B + lado_C) / 2; //Calculo de Semiperimetro.

        areaTriang = sqrt(SemiPerim * (SemiPerim - lado_A) * (SemiPerim - lado_B) * (SemiPerim - lado_C));

        return areaTriang;
    }

    string printArea(float arTriang){ cout << "El area del Triangulo es: " << arTriang << "cm2." << endl; } //Imprime Area :)
}; //Fin Clase Triangulo


//Inicia Main

int main(){

    bandera_Triang triangA;

    system("pause");
} 
nicael
  • 18,550
  • 13
  • 57
  • 90
10110
  • 2,353
  • 1
  • 21
  • 37
  • I also got the same error. I simply updated to the Visual Studio SP1. And also read this for more info: https://msdn.microsoft.com/en-us/library/799kze2z.aspx – Praneeth Peiris Apr 05 '15 at 07:13
  • It is telling you that you have not defined the destructor (~bandera) – cup Apr 05 '15 at 07:20
  • Hi, yes while i was waiting for a reply I took a look and commented the destructor and it compiled... Can you tell me what is wrong with it. THANKS for the replies! – 10110 Apr 05 '15 at 07:26
  • By default, if you do not define the destructor, copy constructor or assignment operator, they are provided for you. So either you do not define the destructor, in which case, one is provided for you or you define a destructor. – cup Apr 05 '15 at 08:05

1 Answers1

0

There are two steps to creating the executable, compiling and linking. During the compilation phase, you sometimes only make a promise, like "there is a function int foo(float)" even though that function isn't part of this compilation unit. The compiler will take your word and only insert a placeholder. Later on, the linker will assemble the different parts of your program and resolve that placeholder. Since it doesn't find the promised function, it errors out.

The promised function is the destructor, which you declared (~bandera_Triang();) but never actually provided. If you didn't promise to provide one, the compiler would have created this special function for you, so I'd suggest you just remove the declaration. In order to let the teacher know you considered this, you can write it like this:

// default dtor is fine
// ~bandera_Triang();

or you could implement it with an empty body.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
  • Hi, The problem is that is an assignment and the destructor must be included (so the teacher know that i am aware that theres a destructor) Could you tell me the write way to use the destructor? Thanks a lot, Sir. – 10110 Apr 05 '15 at 07:30
  • 1
    Thanks again for the assist, sir. Have a nice one. – 10110 Apr 05 '15 at 07:38