Hi, you are defining the same method multiple times, and this is not allowed for obvious reasons.
Instead, what I think you are trying to do is having three objects of type 'one'. If this is the case, you have to define only one constructor (maybe passing data as parameters) and call it as many times as you want from a main method.
class one
{
char q[11];
int a;
public:
char n[15];
one();//this is constructor i suppose...
};
one punch,kick,toss;
punch::one(){q="punch";
a=15;
n="kill";
}
kick::one(){q="kick";
a=15;
n="faint";
}
toss::one(){q="toss";
a=10;
n="k.o.";
}
I know this one is not correct but is something similar possible?
class A
{
int a;
int b;
public:
int c;
int d;
A()
{
a=b=c=d=14;
}
void change(A one,A two)
{
one.a=one.a/2;
two.a=two.a/2;
}
} ;
int main()
{
A p,o;
A::change(p,o);//this one here gives errors
//what is wrong with this???
return 0;
}
I'm not sure why you would want to do it like this. If you just wanted a function to divide a member variable by 2 then.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class A
{
//info
void change()
{
a /= 2;
}
};
int main()
{
A p,o;
p.change();
o.change();
}
If you wanted to do it your way you could make that function static and it would work, but there is no reason for that function to be part of the class anyway. It could just be a free standing function.
If you don't want to call the function on an object obj.func() but instead only mention the type TypeOfObj::func() then the function has to be a static member function.
To make A::change(A, A) into a static function all you need to do is to add static at the beginning of line 13.