0

hello and good morning everyone! im new to c++ and just learnt the header files. I already tried many times to fix the error but when i include the header file in my main, i received an error " undefined reference to `IPhone::IPhone()'". Here is my header file. (im using DEV C++)

#ifndef IPHONE_H
#define IPHONE_H

class IPhone
{
    public :
    IPhone();
};
#endif

This is my cpp file (for the implementation of the header file)

#include "iphone.h"
#include<iostream>
using namespace std;

IPhone::IPhone()
{
    cout<< "object created ";
    
}

Lastly, this is may main to test the class

#include<iostream>
#include "iphone.h"
using namespace std;

int main()
{
    IPhone phone1;
    return 0;
    
}

Thankyou in advance!

  • How did you compile your programs? – MikeCAT Oct 24 '20 at 02:45
  • i run the program with dev C++ – lil poggers Oct 24 '20 at 03:16
  • Are you using cmake, visual studio, ninja? –  Oct 24 '20 at 03:48
  • im using DEV C++ sir – lil poggers Oct 24 '20 at 03:56
  • The reason that people ask you about how you compile is because the error message indicates that your cpp file with `main()` is compiled, but the cpp file with the `IPhone` constructor is either not compiled or not linked. You must instruct your development environment to consider the latter cpp file as well. Perhaps you did not add it to the project? – j6t Oct 24 '20 at 06:52
  • i didnt know that i need to link it. I thought just by #include headerfile.h is sufficient to run the program. Thankyou sir for giving me solutions! i appreciate your time n effort – lil poggers Oct 24 '20 at 11:02

0 Answers0