View Full Version : how to declare a friend variable ?

27th March 2006, 09:57
Is it possible to declare a variable as friend ?

How and where this placement whould be done?

27th March 2006, 10:02
http://www.google.fi/search?q=c%2B%2B+friend+class :p

27th March 2006, 10:13
Thanks fot eh link... before I posted this question I looked and search for it.

I know it is possible to declare friend funtions. Is it possible to declare friend variables ? How ?

27th March 2006, 11:06
But what would a friend variable do? When a function or class is a friend of class X, it can access private members of X objects. But a variable can't 'access' anything. It's just a variable.

What exactly are you trying to do?

27th March 2006, 11:22
I have a QPushButton in a class.

I would like to for example change the text of the button from another class.

I know I can create a function that will allow me to do that, buy I have many buttons, so I do not want to create a function for each of them.

27th March 2006, 16:00
Then maybe your buttons are in a wrong class? :)

Maybe you could make use of QButtonGroup? Identify all your buttons with an id number, and use the id number as a parameter of the text setting function?