0

I write my class with a header file and a cpp file but when I compile my code a get an error

myclass.h file

#ifndef MYCLASS_H
#define MYCLASS_H

using namespace std;

class myclass{
public:
    int a;
    myclass(int);
};

#endif

myclass.cpp file

#include "myclass.h"

myclass::myclass(int a=0):a{a}{}

main.cpp file

#include<iostream>
#include "myclass.h"

using namespace std;
int main(){
    myclass a(12);
    cout<<a.a;
}

I get the fallowing error

C:\Users\Arshi\OneDrive\c++\class_test>g++ test.cpp
C:\Users\Arshi\AppData\Local\Temp\ccpDqz6v.o:test.cpp:(.text+0x23): undefined reference to `myclass::myclass(int)'
collect2.exe: error: ld returned 1 exit status

what should I do

0 Answers0