0

I know this is a stupid question, and I'm 99% sure it has something to do with the way I'm compiling, but I seriously have no idea what I'm doing wrong.

Whenever I try to compile I get stuff like this:

undefined reference to `Test::Test()'
//Test.hpp

#ifndef Test_hpp
#define Test_hpp
class Test {
    public:
        Test();
        Test(int a);
        int get();
        void set(int a);
    private:
        int myVal;
};
#endif /* Test_hpp */
//Test.cpp

#include "Test.hpp"
Test::Test(){}
Test::Test(int a){
    this->myVal=a;
}
int Test::get(){
    return this->myVal;
}
int Test::set(int a){
    this->myVal=a;
}
//main.cpp

#include <iostream>
#include "Test.hpp"
int main() {
    Test t;
    t.set(15);
    std::cout<<t.get()<<"\n";
    t=Test(69);
    std::cout<<t.get()<<"\n";
    return 0;
}
Sidwirb
  • 11
  • 1
  • 3
    You suspect it has something to do with the way you're compiling, and so do I, but you don't say what that way _is_. How are you attempting to compile these files? It's quite possible that you're only compiling main.cpp and not Test.cpp. – Nathan Pierson Oct 08 '21 at 19:35
  • Add the build command line to the question and we can probably tell you where in that mammoth omnibus of an Q&A used as a duplicate (and it almost certainly is a duplicate because it covers freaking everything) the answer to your question lies. – user4581301 Oct 08 '21 at 20:00

0 Answers0