class prototype

hi experts,
how to declare my class prototype if i have the following class...
1
2
3
4
5
6
7
8
class A{
 friend void B::test();  //error cant find
};

class B:public A{
public:
 void test();
};


as u know i cant declare class B before A because B inherit from A..
Any idea to solve??

Thanks for reading...
Why exactly does B::test() need to be a friend? It can already access stuff inside of class A since B derives from it publicly.
err this is because...
i have something like this....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class A{
 friend void B::setSalary();  //error cant find
private:
 double salary;
};

class B:public A{
public:
 void setSalary();
};

class C:public A{
 friend void B::setSalary();
};


so, like this i can set all salary value that inherit class A....
its like the class A is Employee, class B and C is worker like clerk, manager, supervisor and accountant...
and accountant will set salary for them....

*EDITED..
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class A;
class B;
class C;

class A{
 friend void B::setSalary();  //error cant find
private:
 double salary;
};

class B:public A{
public:
 void setSalary();
};

class C:public A{
 friend void B::setSalary();
};


Try this instead
Last edited on
spaggy: nope, its not working..
i tried before it will cause you same error cant find the function...
oops sorry. You'll want the class B to be declared before class A but because B is derived from A you'll run into another compilation error. It's a cyclical dependency. The only solutions i know be to either make B a member class of A or remove the inheritance from B. I would lean more towards not having B being derived from A (maybe you could add a higher inheritance level, if you really wanted to)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class A;
class B;
class C;

class Base
{
protected:
	double salary;
};

class B: public Base
{
public:
	void setSalary();
};

class A: public Base
{
	friend void B::setSalary();
};

class C :public Base
{
	friend void B::setSalary();
};


This has the same effect i think. So basically it's normally impossible to modify the salary from outside the class(e.g C can't change A's salary) but B(the accountant) can
Yes, make it protected instead of private.
shit.. i think whole nite but cant get this idea.... thx alot dude...
Topic archived. No new replies allowed.