So you have the declaration right, you just have to not stop. Just as the name itself is a declaration
so is the name itself a declaration.Code:int foo(int x); //function declaration
Code:class Foo; //class declaration
So you have the declaration right, you just have to not stop. Just as the name itself is a declaration
so is the name itself a declaration.Code:int foo(int x); //function declaration
Code:class Foo; //class declaration
I see and why do I need the ' :: ' operator?This is also incorrect. The correct syntax to call a static method is:
attack::use
When do I need this and when do I need the ' . ' operator?
I just tested it, it won't work.But A does not store an object of B, so the definition of B is only needed when defining A::doNothing. C_ntua's point is that that is one example where defining the member function inline will not work, but defining it outside of the class definition will work, assuming that a forward declaration of B is used before defining A. Admittedly, I did not consider this possibility.
If I don't declare class B above class A, I can't have a method in class A that uses class B. Even if I only declare the method in the class and define the body of the method below both classes, I get an error.
This is pretty tricky and will probably cause me headaches in the future.
And when creating a library, I'd just put the definitions of these methods below the class, while still in the same namespace?
As for the methods taking references to an object, I forgot that you can just add * and & to a variable call.
In this case, I'd make a method which takes a memory address of an object and pass that to the method, like this?
Code:void Test(Object& obj) { // Do Stuff } . . . Object obj; Test(&obj); . . .
attack::use() means "call the member function use in CLASS attack". If you instead have attack.use() it means "call the member function use in the OBJECT attack".
A static member function is one that can be used without actually having an object of that class. It is a way to have functions that doesn't actually work on an object, but still belongs to the class in some way.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.