I am writing a simple program to compile from the command prompt. There is an app1
program that uses a class located in a separate file. The class sample1
has a header file sample1.h
where all the function declarations exist. The sample1.cpp
file contains the function definitions.
app1.cpp
:
#include <iostream>
#include "sample1.h"
using namespace std;
int main()
{
sample1 t;
cout<<"The program is ending"<<endl;
return 0;
}
sample1.h
:
#ifndef SAMPLE1_H
#define SAMPLE1_H
class sample1
{
public:
sample1();
};
#endif
sample1.cpp
:
#include<sample1.h>
#include <iostream>
using namespace std;
sample1::sample1()
{
cout<<"This error sucks"<<endl;
}
I am compiling this program using Windows Subsystem for Linux. However, when I try to compile with g++ 'app1.cpp' -o app1
, I get this error:
I get that the error is telling me that the program cannot find the constructor sample::sample()
but why is that? I included the header file in the program. These 3 files all exist in the same folder.