Building the basics of any c++ program.

Good morning programmers,

I'm trying to put the basics of any c++ program consists of 3 files. One for the main function, and one for class definition and another for the member functions of the class.

So I wrote this for the main file:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include"sort.h"
using namespace std;

int main()
{
    sort task;


    
system("pause");
return 0;
}


And this for sort.h:
1
2
3
4
5
6
7
8
9
10
using namespace std;

class sort
{
    public:
        sort();
        ~sort();
        
    private:
};


And this for sort.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include"sort.h"
using namespace std;

//--------- Constructor ----------
sort::sort()
{
}

//--------- Destructor -----------
sort::~sort()
{
}


But I get an error when I compile the program. I have checked it so many times and couldn't figure it out.Could you help me?

I need a strong basics to continue learning more complicated stuff in C++. If you have any advice to make it well-built.
Sometime #ifndefine is added in the header file, is it necessary here?

Thank you!
Don't put using stuff in your header files.

What exactly is the error you are getting?
Hi Firedraco,

OK, I deleted "using". This is the error:

In function 'int main()':
'sort' undeclared (first use this function).

I'm using Dev-C++ by the way.
That's odd. You shouldn't be getting that error...I have no idea why that would be happening unless somehow sort.h isn't getting included, but that would be giving you a different error.

Btw, in this case your wouldn't need #ifndef stuff in your header file, but it's probably a good idea to learn to do it anyway.
I guess I found it! The problem was with the word "sort", it seems like reserved word.

I had changed it -in the program code- to "sort1" and it works!!! Hah :)
Topic archived. No new replies allowed.