class

if i were to have a class called class it header would be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef CLASS_H
#define CLASS_H


class class
{
    public:
        class();
        virtual ~class();
    protected:
    private:
};

#endif // CLASS_H 


and its cpp file would be
1
2
3
4
5
6
7
8
9
10
11
#include "class.h"

class::class()
{
    //ctor
}

class::~class()
{
    //dtor
}


with this i can make new funcs in my class. ok here is the question. what is making them connected to each other??
Last edited on
Ceset wrote:
what is making them connected to each other??
The thing before the double colons on lines 3 and 8 of the cpp file.
so it doesnt matter what name u give to the .cpp file right. it only helps u keep orginized
Last edited on
It really does not matter, as long as the .h is split from the .cpp .
It can also be a completely random name, even on a different drive.
The compiler will "match" them by the class's name.
First off, you can't have a class named class. class is a reserved word.

Not sure what you mean by "connected to each other".
You have to create an instance of (instantiate) the class.

Let's rename your class to Foo to avoid the use of a reserved word.
1
2
3
4
5
6
7
int main ()
{  Foo   a;     //  this is an instance of Foo
                     //  Its ctor will be called automatically to initialize it
  a.somefunc();   //  Call somefunc() which is a member of Foo. 
                           //  somefunc() will operate on instance a
  return 0;           //  Foo's dtor is called to cleanup instance a
}


ty all
and AbstractionAnon change it to example.h if u want. doesnt matter it is just a name i used for my question. it is not like someone is going to create a class named class. thats so funny

and using the word "connected" at there is nonsense. i will change it.
The class name, header name, and cpp file name can all be different.
i actually mark this topic as solved but one more thing come to my mind and didnt think it is necessery to start a new one.

and i think one can use one header file with many .cpp files right. is it possible??
for example:
1
2
3
4
5
ex.h -> ex.cpp   ||   ex.h-->ex.cpp
                          |_>ex_func1.cpp
                          |_>ex_func2.cpp
                          |_>ex_func3.cpp
                          |_>ex_func4.cpp


like that

EDIT: Maybe i should ask this que in another topic
Last edited on
Yes that is possible. Though it is usually not advised unless your class is enormous.

And if your class is enormous you might want to consider breaking it up into smaller classes.
lots of thanks. i feel like a beer wont be illegal for me anymore:D
Last edited on
Topic archived. No new replies allowed.