I'm not sure I understand the question but,
As long as you say "public:", any method and data member can be accessed simply by using "."
thus: object1.function1(); object1.mX = 50; etc
so if you need to call function in main.cpp, just place them under public
However, when you use "private:" you essentially say, only methods of this class can access this data member.
This has the advantage that you can place checks along the way.
eg:
object1.mX = 50; will not work, because the data member is private.
However you can get around this.
As I said before, data members are still visible to methods of that class.
thus you can write :
1 2 3 4 5 6 7 8 9 10 11
|
void class1::function1(int x)
{
if (x > 0 && x < 100)
{
mX = x;
}
else
{
std::cout << "... Error, out of bounds ..."
}
}
|
As for the pointers, yes you can. You can make pointers of objects like any other pointer.
However, there is a syntax difference:
className* objectName = new object1;
but then to using the indirection operator, you get this clumpsy syntax:
(*object1).function1();
therefor the membership operator is created which is the same as the above syntax:
object1->function1();
for deletion simply do "delete object1".
This will call the destructor.
EDIT: I should probably mention too that classes are by default private, while struct is by default public.
Double Edit: Only now saw your answer, sorry :) damn refresh on the browser :p.
Well indeed that you can do as well.