The Different using "include" and "class"

May 3, 2009 at 2:52am
Dear,

I don't really understand the difference between using include and adding a class.
For example: using include :
+++++++++++++++++++++++
// First case
#include "myA.h"

class myB {
.
.

}

+++++++++++++++++++++++
//Second case
class myB {
class myA;

.
.

}
+++++++++++++++++++++++

Thanks and I would look forward to your information.

Abu.
May 3, 2009 at 7:12am
Using #include copies the contents of that file into the file you are currently in. Since the header files usually have the class declarations in them, that would give you something like:

1
2
3
4
5
6
7
class myA {
    // ...
}

class myB {
    // ...
}


Your second case seems like it is trying to declare a "prototype" of myA inside class myB...? That isn't really comparable and doesn't make sense to me.
May 3, 2009 at 9:57am
1
2
3
4
5
6
7
8
//Second case
class myB {
class myA;

.
.

}




if you are talking about this.. it may be called association in uml terms..
it can of two type aggregation and composition.

giving an example of association..
department has professors(aggregation, as destroying dept doesnt destroy professors)
university has a department (composition, as destroying university destroys department also).

but it will make sense if you declare myA or make an object of myA inside myB.
Topic archived. No new replies allowed.