-2
I’ve been trying to solve a mistake since yesterday, but so far I don’t know what I’m doing wrong when implementing a C class++.
I put the class with the prototypes in an extension file . h (header) and the methods in one of the same name only of extension . cpp, I did the simplest possible to know where the error is but so far I could not solve:
test. h
#ifndef TESTE_H
#define TESTE_H
class Teste {
public:
void mostra();
};
#endif
cpp testing.
#include "teste.h"
#include <iostream>
void Teste::mostra() {
std::cout << "Isso é um Teste\n";
}
main.cpp (I think the mistake is not here, but I put it just to be sure)
#include "teste.h"
int main() {
Teste *test = new Teste;
test->mostra();
return 0;
}
Error:
undefined reference to `Teste::mostra()'
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
It worked here: https://replit.com/@acwoss/Differentleandeskscan#main.cpp
– Woss
The problem is not the code, it is the way you are compiling and generating the executable. The code of the.cpp test module is not being linked in the final executable. Add the commands you are using to compile to the question, to give a final answer.
– epx