0

Basically, I have to build two archives one is named Ponto2D.hpp and the other Ponto2D.cpp

Ponto2D.hpp:

#ifndef PONTO2D_H
#define PONTO2D_H
#include <iostream>
#include <cmath>
using namespace std;

struct Ponto2D{
    double posx, posy; 

    Ponto2D();

    Ponto2D(double, double);
    double calcular_distancia(Ponto2D* ponto);
}; 
#endif

Ponto2D.cpp:

#include "Ponto2D.hpp"
#include <iostream>
#include <cmath>

Ponto2D::Ponto2D(double x, double y){
    posx = x; posy = y;
}

double Ponto2D::calcular_distancia(Ponto2D* ponto){
    double distx = abs(this->posx - ponto->posx); //
    double disty = abs(this->posy - ponto->posy);
    return sqrt(distx * distx + disty * disty);
}

And when I try to use it's commands i get this error:

undefined reference to `Ponto2D::Ponto2D(double, double)' Any ideias of how to solve this?

  • 2
    How are you compiling the code? What compiler are you using? – NathanOliver Oct 29 '21 at 16:26
  • This is a university project so I have to use their compiler to run the code and get my grade, I guess they use g++ – Fabricio Lopes Oct 29 '21 at 16:28
  • What arguments do you pass to the compiler. You need to tell it to compile the cpp file that contains `main` and the cpp file that contains the definitions of the member functions. related/dupe: https://stackoverflow.com/questions/3202136/using-g-to-compile-multiple-cpp-and-h-files – NathanOliver Oct 29 '21 at 16:32
  • 1
    You didn't compile Ponto2D.cpp into the program. The computer is only compiling main.cpp – user253751 Oct 29 '21 at 16:34

0 Answers0