Error while trying to compile files. h in c++

Asked

Viewed 802 times

0

The code is this:

#include "stdafx.h"
#include "classeID.h"
#include <iostream>
#include <string>

using namespace std;

int main() {
    id label("default", 0);
    cout << "Nome: " << label.getName() << "\n";
    cout << "Idade: " << label.getIdade() << "\n";
    return 0;
}

//arquivo .h----------

#ifndef classeID_H
#define classeID_H
#include <string>
using namespace std;
class id {
private:
    string name;
    int idade;
public:
    id(string n, int i);
    ~id(void);
    string getName();
    int getIdade();
private:
    void welcome();
};
#endif // !classeID_H

//arquivo de implementação da classe id(classeID.cpp)----------

#include "classeID.h"
#include <iostream>
#include <string>

using namespace std;

id::id(string n, int i) {
    welcome();
    this->name = n;
    this->idade = i;
}

id::~id(void) {
    cout << "Objeto label destruido.\n";
    system("pause > null");
}

void id::welcome(void) {
    cout << "Bem vindo\n";
}
string id::getName() {
    return name;
}

int id::getIdade() {
    return idade;
}

I use Visual Studio as IDE. The error it returns to me is LNK2019. I have searched for this error and understood nothing. My doubt is also on how the file . h associates to the file classeID.cpp. Anyway just know that I know nothing rsrs...

  • Thus, the term used is not to compile .h, it is only included in the source that imports it Verbatim. I will look here for an answer that talks a little about the C/C compilation process++

  • Read a little more about how the C processor works is how the CPP works in that reply

  • 1

    Works well in Codeblocks, it’s even Linker configuration in Visual Studio

  • This other answer may direct you better: https://stackoverflow.com/q/19886397

  • @Isac I believe that the classID.cpp is not being compiled

  • 1

    It is capable yes, it has to confirm that the solution is compiling and linking all the files

  • After_, which objects files are generated? Object file has extension .obj in Visual Studio (already in gcc are the .o)

  • 1

    Put the whole code, including line and all, preferably copy the whole log, just so we can know what’s missing

Show 3 more comments

1 answer

0


I found the problem by looking at the contents of the page https://stackoverflow.com/q/19886397 @Jefferson Quesado. The classeID. h and classeID.cpp files have never been properly associated with the main file POO.cpp. I recreated the files within the same solution and the program compiled normally. Solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.