invisible.hippo
Arch-Supremacy Member
- Joined
- Nov 8, 2008
- Messages
- 17,902
- Reaction score
- 315
Hi, i am learning class , structure and union
However i dont know how to apply it in practice. I do know that the members in a class are private and in structure are public.
E.g would be
However i dont know how to apply it in practice, like if i were to change the member in class to be public wouldnt it be same as a structure? If by doing so what would be the difference then?
Secondly, i come across that class can do overload(which i have no clue and still trying to read up more) which i believe structure does not have(i never come across overloading in structure).
I believe that all for the difference. I hope someone can
1) tell me is my understanding correct
2) hopefully show me the practical difference between class and structure ( more in dept)
i feel that most tutorial video/guide are too brief(they only explain, but did not really put into oop concept)
However i dont know how to apply it in practice. I do know that the members in a class are private and in structure are public.
E.g would be
Code:
// Program 1
#include <stdio.h>
class Test {
int x; // x is private
};
int main()
{
Test t;
t.x = 20; // compiler error because x is private
getchar();
return 0;
}
// Program 2
#include <stdio.h>
struct Test {
int x; // x is public
};
int main()
{
Test t;
t.x = 20; // works fine because x is public
getchar();
return 0;
}
However i dont know how to apply it in practice, like if i were to change the member in class to be public wouldnt it be same as a structure? If by doing so what would be the difference then?
Secondly, i come across that class can do overload(which i have no clue and still trying to read up more) which i believe structure does not have(i never come across overloading in structure).
I believe that all for the difference. I hope someone can
1) tell me is my understanding correct
2) hopefully show me the practical difference between class and structure ( more in dept)
i feel that most tutorial video/guide are too brief(they only explain, but did not really put into oop concept)
