This question already has answers here:
When do I need anonymous class in C++?
(6 answers)
Unnamed classes
(2 answers)
Closed 9 years ago.
I have been exploring more C++ and encountered a phenomenon like Unnamed classes.
class : public classB{
public:
protected:
private:
};
How are these classes useful? Is it like the concept of lambda functions?
I would like to know the purpose of such classes. The other threads don't really show any usefulness of the feature.
Related
This question already has answers here:
What "CV_EXPORTS_W" means
(2 answers)
Closed 5 years ago.
I'm trying to understand functionality of OpenCv library. I saw following strange type class declaration code here.
class CV_EXPORTS_W Subdiv2D
{
// code here
};
I don't understand, What does Subdiv2D do with class?
The Subdiv2D is the name of the class. The CV_EXPORTS_W part is probably some macro or an alias specific to Windows implementation.
This question already has answers here:
When should you use 'friend' in C++?
(31 answers)
What's the difference between friendship and inheritance?
(4 answers)
Closed 5 years ago.
I am not exactly sure what the use of a friend function or class is when you can easily just use inheritance (parent/child classes)? From my understanding, a friend function or class allows a non-member function to access the members of another class that it is declared a friend of. Similarly, a child class can access the members of a parent class. I am wondering, in which situation would you pick one over the other?
Because you may want to use some private functions/member of a class without being a child of it....
You should read more about inheritance. You can't consider inheritance as a solution to access "members of a class" as you mentioned.
This question already has answers here:
Why do Python classes inherit object?
(6 answers)
Closed 6 years ago.
I am learning to make classes using template codes and one of them is coded with what looks like inheritance syntax:
class KNNLearner(object):
What is the purpose of (object) here?
In python everything is an object, an object is an object. You can also create Meta-classes to change some behavior of your objects/object to implement something.
In you case KNNLearner(object) the (object) permits you to pass the class that you want to KNNLearner to inherit.
This question already has answers here:
Package accessibility for function and/or class
(6 answers)
Closed 9 years ago.
I'm wondering about how is it possible to set the package level access for a method in cpp.
Considering the following Java class
package Foo;
class Bar{
public Bar(){}
void bas(){}//package access, how in cpp?
}
the equivalent for cpp would be
namespace foo{
class bar{
public: bar(){};
//so now how would I set the package access specifier for bas?
};
};
As far as I know C++ has not package access level modifiers. But maybe friends class will be usefull in your case?
This question already has answers here:
Alternative virtual function calls implementations?
(11 answers)
Closed 9 years ago.
I read in a book that polymorphism is implemented in c++ by three levels of pointers(using vtable) but are there other methods of implementing it in c++ .
Virtual functions can also be implemented directly with function pointers like this.
struct A
{
void (*foo)(A *thiz);
void (*goo)(A *thiz, int x);
};
But obviously this is less efficient than the normal implementations. And actually C++ implementations may differ a little when dealing with multiply inheritance and virtual base classes.