Please i got a problem linking my .cpp files together in my c++ project. I dnt knw how to specify the file path for #include . Please any help?

Recommended Answers

Please could you include an example to your problem? It's kind of hard to find out where you are going wrong, but, here is an example (of what I assume you are trying to do):

// Test.h 

class Test {

    public: 

      Test(); // constructor 

      void doSomethingCreative();

}; …
Jump to Post

All 3 Replies

Please could you include an example to your problem? It's kind of hard to find out where you are going wrong, but, here is an example (of what I assume you are trying to do):

// Test.h 

class Test {

    public: 

      Test(); // constructor 

      void doSomethingCreative();

};

And then your implementation of this class:

#include "Test.h" // assuming the header file is called "Test.h"

Test::Test()
{
   // constructor implementation
}

void Test::doSomethingCreative()
{
    // Method implemenation
}

At compile time, we just need to compile the .cpp file over the .h So, therefore your main will look something like so:

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

int main(int argc, char *argv[]) {

   Test t;

   t.doSomethingCreative();
}

To compile, again, using GCC would be something like:

g++ Test.cpp main.cpp -o main
./main

Hope this helps slightly.

U are awesome man! Thanks, u've done it all. +u solved a little problem i had with oop c++

No problem :) Please make this thread as solved and give rep to those who helped you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.