Click here to Skip to main content
14,978,482 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Accurate interpretation and evaluation of this "or condition": while ( x < 1 || x > 8 ) Pin
Mircea Neacsu26-Jun-21 1:25
mvaMircea Neacsu26-Jun-21 1:25 
GeneralRe: Accurate interpretation and evaluation of this "or condition": while ( x < 1 || x > 8 ) Pin
Otto Medina26-Jun-21 18:51
MemberOtto Medina26-Jun-21 18:51 
AnswerRe: Accurate interpretation and evaluation of this "or condition": while ( x < 1 || x > 8 ) Pin
Aghast (nj)26-Jun-21 3:13
MemberAghast (nj)26-Jun-21 3:13 
GeneralRe: Accurate interpretation and evaluation of this "or condition": while ( x < 1 || x > 8 ) Pin
Otto Medina29-Jun-21 2:30
MemberOtto Medina29-Jun-21 2:30 
QuestionHow do I access private variable of an object ? Pin
Member 1496877116-Jun-21 3:19
MemberMember 1496877116-Jun-21 3:19 
AnswerRe: How do I access private variable of an object ? Pin
Mircea Neacsu16-Jun-21 3:23
mvaMircea Neacsu16-Jun-21 3:23 
GeneralRe: How do I access private variable of an object ? Pin
Member 1496877116-Jun-21 5:50
MemberMember 1496877116-Jun-21 5:50 
AnswerRe: How do I access private variable of an object ? Pin
Mircea Neacsu16-Jun-21 6:12
mvaMircea Neacsu16-Jun-21 6:12 
Member 14968771 wrote:
I think I need to read-up on "friend" - that semms to be the real OOP ticket

On the contrary: that might take you into a non-OOP design.

The idea of using public member functions is to make your code independent of internal implementation details of other classes. In your case, a class representing a rectangle might keep a corner of the rectangle and its dimensions. Another one might keep two opposite corners or some other combination. If you try to access private members of the class your code will need to change when or if the implementation of the rectangle changes. If you stick to using only public interface, the internal details of the rectangle class may change but your code will remain the same.

You cannot "buy" your way inside a class using a friend declaration. Just like in real life, the friendship is not a symmetrical relation. If you put a friend QRect declaration inside your class that doesn't give you any special access rights. It gives access rights to QRect to your class but obviously QRect is not going to use those rights. You would need to modify the QRect header file to insert a friend declaration mentioning your class. This is very intrusive and basically defeats the purpose of OOP design.

I cannot make an OOP design course here, but there are some pretty good references available.
Mircea

GeneralRe: How do I access private variable of an object ? Pin
David Crow16-Jun-21 6:37
MemberDavid Crow16-Jun-21 6:37 
GeneralRe: How do I access private variable of an object ? Pin
Member 1496877117-Jun-21 6:41
MemberMember 1496877117-Jun-21 6:41 
AnswerRe: How do I access private variable of an object ? Pin
Richard MacCutchan16-Jun-21 6:58
mveRichard MacCutchan16-Jun-21 6:58 
AnswerRe: How do I access private variable of an object ? Pin
RedDk16-Jun-21 7:22
MemberRedDk16-Jun-21 7:22 
AnswerRe: How do I access private variable of an object ? Pin
CPallini16-Jun-21 23:27
mveCPallini16-Jun-21 23:27 
GeneralRe: How do I access private variable of an object ? Pin
Richard MacCutchan17-Jun-21 0:35
mveRichard MacCutchan17-Jun-21 0:35 
GeneralRe: How do I access private variable of an object ? Pin
CPallini17-Jun-21 1:32
mveCPallini17-Jun-21 1:32 
GeneralRe: How do I access private variable of an object ? Pin
Member 1496877117-Jun-21 6:36
MemberMember 1496877117-Jun-21 6:36 
GeneralRe: How do I access private variable of an object ? Pin
Richard MacCutchan17-Jun-21 6:40
mveRichard MacCutchan17-Jun-21 6:40 
GeneralRe: How do I access private variable of an object ? Pin
CPallini17-Jun-21 7:43
mveCPallini17-Jun-21 7:43 
AnswerRe: How do I access private variable of an object ? Pin
Magnus Forslund15-Jul-21 2:19
MemberMagnus Forslund15-Jul-21 2:19 
QuestionPass a function with parameter Pin
Member 1496877115-Jun-21 10:35
MemberMember 1496877115-Jun-21 10:35 
AnswerRe: Pass a function with parameter Pin
Greg Utas15-Jun-21 11:38
mvaGreg Utas15-Jun-21 11:38 
GeneralRe: Pass a function with parameter Pin
Member 1496877115-Jun-21 13:30
MemberMember 1496877115-Jun-21 13:30 
GeneralRe: Pass a function with parameter Pin
Greg Utas15-Jun-21 13:39
mvaGreg Utas15-Jun-21 13:39 
GeneralRe: Pass a function with parameter Pin
Member 1496877115-Jun-21 15:23
MemberMember 1496877115-Jun-21 15:23 
GeneralRe: Pass a function with parameter Pin
Greg Utas16-Jun-21 0:22
mvaGreg Utas16-Jun-21 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.