Using private functions

Hi,

I have 2 class, my first class is reading a text file and editting it,

For example if file's first line is :
"    Heyyy  What's  , up!!!!    "

it turns it :
"Heyyy What's,up!!!!"


my firstclass,
1
2
3
4
5
6
7
8
class A{

public:
    read(fsteam filename);
private:
    edidIt(...);

}


like this. edidIt is calling from read fuction.

(edidIt function is calling 3-4 function from first class's private members, so I dont want to copy paste)

And my second class have different logic from first class A, but I need to call edidIt function in my second class. (I can't call read function) What should I do?

Do I have copy edidIt function from first class and paste second class? (I dont want to do it)

Thanks.
Last edited on
You can make the second class a friend. By doing this, the second class will have access to the editIt function of the first class.
But my first class and my second class are in diferent files. And ı have no global function(and I can't do global because it is forbidden). So ı think ı can't use "friend".

Do u have any other idea?
Last edited on
You can still make the second class a friend of the first one.

1
2
3
4
5
6
7
8
9
class A{

public:
    read(fstream filename);
    friend class B; // makes class B a friend
private:
    edidIt(...);

};


Now class B will have access to class A's editIt function.

If this is still unclear, post all your header and cpp files.
Last edited on
Topic archived. No new replies allowed.