Holidays and Hobbies
  • Home
  • Brasil
  • Rome
  • Paris
  • Fabio
    • Data Science Blog
    • Music
    • Rubiks Cube
    • Astronomy
    • Art
    • Unicycle
    • English Pope
    • Flying
    • If I Ruled The World
    • Fusion
  • Local
  • Tenby
  • Keswick
  • Mark
  • Store
  • Contact
  • cplusplus

Using headers .h and implementation files

8/28/2018

 
A typical object oriented program will have:
  1.     myfirst.h - the header include file
  2.     myfirstlib.cpp  - the implementation, compiled to myfirstlib.o
  3.     myfirst - the compiled (and linked program)
Example:

// This will be #include "myfirst.h"
class myfirstClass {
public:
    int a_number;
    void my_func01();
};

// This would be in the myfirstlib.o library, the implementation
void myfirstClass::my_func01() {
    std::cout << "This is in my_func01" << std::endl;
}

// And this of course the main body
#include <iostream>
int main() {
    myfirstClass mine;
    mine.my_func01();

}



The Makefile when you have headers and libraries

So the Makefile would need entries for this like so:

bin/running :    bin/myfirst.o    bin/myfirstlib.o
    $(CC) -o bin/myfirst  bin/myfirst.o bin/myfirstlib.o

bin/myfirstlib.o : src/myfirstlib.cpp  include/myfirst.h
    $(CC) -c -o bin/myfirstlib.o   src/myfirstlib.cpp
bin/myfirst.o : src/myfirst.cpp include/myfirst.h
    $(CC) -c -o bin/myfirst.o src/myfirst.cpp






Comments are closed.

    Author

    A look at C++ From scratch.

    RSS Feed

    Archives

    August 2018

    Categories

    All

    RSS Feed