--Do this:
Code:
class A
{
public:
int a;
void show(int i) {std::cout << a;}
};
it compiles normally. As this one:
Code:
class A
{
public:
int a:
void show(int i);
};
void A::show(int i) {std::cout << a;}
I ll make a guess which MAYBE is correct (don't have g++ at the moment to test it).
Code:
class A
{
public:
void doNothing(B par) {;}
};
class B
{
int b;
};
The above might not work, because B was declared below A. So you might need this:
Code:
class A
{
public:
void doNothing();
};
class B
{
int b;
};
void A::doNothing() {B b();}
which I believe should work. In C# you don't have to worry about these thinks
--No, you don't need an extra variable. I don't fully understand what you mean. In C++ you can do MORE than C# when it comes to passing objects to methods. You can do all the below:
Code:
void add(obj o);
void add(obj& o);
void add(obj* o);
Now, in the first two you will pass an object normally, as in C#. Like:
in the third method you need to pass a pointer. Like:
Code:
obj o();
obj* ptr_o = &o;
add(ptr_o); //or just add(&o);
The first two methods differ only on the HOW the object is passed. Everything else is as in C#. The C# way is the second, passing the object by reference. The first makes a copy of the object. It is like passing an object, making a copy and using the copy.
--Well, you can make a method static. Like:
Code:
class attack
{
public:
int damage;
static use() {...}
};
...
int main() {
character ch1(), ch2();
attack.use(ch1, ch2);