Terminology for a class who has something as a member [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
In object oriented programming terminology, I can simply say:
- Member: I mean to say a member of (this) class (which I'm referring to)
But I don't know what is the correct terminology for this:
- ? : I mean to say a class who has (this thing I'm referring to) as a member
Maybe I can use owner or parent. Any idea?

FWIW the C++ standard calls this "containing object" or "containing class object" in a couple of places. It never formally defines the term though.
I guess you can call the corresponding class "the containing class".

In good old days there was a term nesting used in a variety of ways( nesting scope, nesting namespace, nesting class, nesting function...). I don't know if it is still widely used, but IMHO it does the purpose.
Regards,
FM.

I ended up using this as the most clear:
... classes which own this class as member ...

Related

Does using this "shortcutting function" is a good practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a event based communication system, and this is the simplifed version of it:
class A: contains elements derived from class B
class B: has a pointer to its owner A
So when a B wants to communicate with other B-s, it calls A's Broadcast() method:
m_owner->Broadcast();
But I was wondering:
Should I make a protected Broadcast() method for B, which is just this:
m_owner->Broadcast();
Pros:
Instead of m_owner->Broadcast() I can write just Broadcast()
this makes the code cleaner.
Cons:
There will be +1 function calling in the procedure.
But this can be avoided by making the method inline
Is this a good practice? Why yes and why not?
In a situation that you have described, it probably indeed does not make much difference.
But in future you may find that you will need to add extra code to each place where Broadcast is called, for example logging or mutex locking. In this case, a separate function will be really useful.
Also you mention that you have classes derived from B. If this is a derived class that calls m_owner->Broadcast(), and m_owner is a base class field, then this is not a good pattern. Derived classes should better access parent's protected functions, not directly data members.

Using : and :: in C++ without confusing [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Both : and :: punctuations in C++ can bind ownership of function within class, or subclass within base class. But it's not fully clear when to use each in general, and which to put in header and which in cpp source files (if this is a matter of personal flavor, please tell more common convention). Concise example would be appreciable so much!
Please correct me if I am wrong or not precise enough, and list other cases if I missed some for using : and ::
Thanks in advance.
bind is not the best word to use for this.
:: scopes functions and so on.
For example std::cout says there is something called cout in a scope (namespace, class...) called std.
: does not do this and can be used in a variety of ways.
It can follow an access specifier, for example public:.
It is also part of the ternary conditional x ? y : z

Is there any way to restrict inheritance? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Please provide a simple solution to restrict inheritance in C++.
Yes! As of C++11, there's a final specifier you can use to indicate that a class cannot be inherited from:
class DontInheritMe final {
// This class cannot be inherited from.
};
If you have experience in Java, the final keyword in C++ in this case works the same was as final classes in Java.
If u really dont want to inherit a class,then just make its member variables and member functions as private ,if other class tries to inherit it they cant have access to its funtions and variables anyways.
But using final is a better option

What is class as opposed to Object Oriented Programming? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
sorry to bother but I'm a newbie programmer and has just been starting on c++ course. The reason I asked this question is because I've been hearing on OOP and its relation to class.
So my question is:
Does class actually simplify the programming code just because it groups up all related functions into one single "object" thats called "class" ?
One more thing is that...
Why do we create class inheritance when we could use one class and derive all functions from that one class alone?
Sorry to bother.
Newbie programmer.
"Does class actually simplify the programming code just because it groups up all related functions into one single "object" thats called "class" ?"
The main idea is to encapsulate state (== data) with operations that can be applied to it into a single class type.
Yes, that simplifies programming code, because there are certain interfaces/operations that can be used with this type.
"Why do we create class inheritance when we could use one class and derive all functions from that one class alone?"
Derived classes may introduce different behavior as inherited from their base class. There are many uses when you want to change that behavior, without inventing new function names all the time (or just add numbers to them).

Why C++ allows to give more restrictive access to a derived class method? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This link talks about allowing more restrictive access to a derived class method.
Q. What is the reason for allowing this in C++?
Languages such as Java & C# don't allow it. Is it useful in some cases? If so please help me understand.
It has more to do with it never being disallowed. And now it's too late: too much code would break. Do remember that C++ is a considerably older language than either Java or C#.
But the C++ philosophy inspires you to ask "why disallow it?". It could even be useful: some folk exploit it and make overridden methods private. The amount of documentation you should attach to a private method can be significantly less than a public method. This means you don't repeat yourself and are compelled to rely on the public / protected method in a base class for comments.