help me plz

how can I save the implemntaion file with main .cpp in the same directory
I wanna my output gets appear
Can you rephrase please
Hi there,

I'm afraid you'll need to be a little bit more specific about your problem.
Could you perhaps tell us a little bit more about the problem?

If you want to have multiple .cpp files, you need to compile them together with main.cpp.
Also, you need a .h file containing the definitions of your functions/classes so you can include it in your main.cpp:

1
2
3
4
5
6
//implementation.h
#ifndef IMPLEMENTATION_H //include guard
#define IMPLEMENTATION_H

void my_function(int a, double b);
#endif 



1
2
3
4
5
6
7
8
//implementation.cpp
#include <iostream>
#include "implementation.h"

void my_function(int a, double b)
{
    std::cout << a << " / " << b;
}


1
2
3
4
5
6
7
8
9
10
11
//main.cpp
#include "implementation.h"

int main(int argc, char** argv)
{
    int x,y;

    my_function(x, y);

    return 0;
}



On g++, compile as follows:

g++ -Wall --pedantic main.cpp implementation.cpp


Hope that helps.

All the best,
NwN
I mean when I write the class in a separate file .seprate the interface from the implementation ..the output dosen't appear ..my teacher said that I'm not save it in the same directory and I don't understand what she means
Topic archived. No new replies allowed.