-4

I have two cpp files and two header file, they are a.cpp, b.cpp, a.h and b.h respectively. I have a method defined in the a.cpp file and I would like to call the method in the b.cpp file. How do i go about doing it? Please advice Thank you.

Can i make use of the friend function to do so?

user3306996
  • 421
  • 2
  • 4
  • 15

2 Answers2

1

Assuming that you have function prototypes in your header-files and the definitions in your cpp-files. And that you have included a.h in a.cpp and b.h in b.cpp.

Simply add #include "b.h" in a.h to reach the functions in b.cpp.

robbannn
  • 5,001
  • 1
  • 32
  • 47
1

Add the line

    #include "a.h"

in "b.h" . And Compile ur code with

    g++ a.cpp b.cpp 

Also,

    #include "a.h" in a.cpp
    #include "b.h" in b.cpp