Strange type class declaration [duplicate] - c++

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.

Related

How to use the type mentioned in input for creating an object? [duplicate]

This question already has answers here:
choosing appropriate specialized template at runtime
(2 answers)
Create objects from template, type is entered by user input c++
(4 answers)
Closed 3 months ago.
Say I have a templatized class
template<class T>
class MyClass
{
...
}
Now let's say for the sake of simplicity, that the input explicitly mentions that the following data shall be of what type:
for example
int
1 2 3 4 5
or
float
1.5 2.3 4.2 5.9
Now I want to create an object based on the type mentioned in the input
Something like
MyClass<type_mentioned_in_input> obj;
How do I achieve this?
Based on my lesser understanding of C++, here is what I tried:
Create an abstract base class for the MyClass
Mention all the member functions of MyClass as pure virtual functions in the abstract base class
Dynamically initialize an object of the base class at runtime
Clearly this method not only increases the complexity, but also fails with templates.
What should be the desired what to execute this?
You can't:
template are compiler time, the specific content between < .. > is replaced when you build, and that can not be modified runtime based on the input.
The solution to your problem (about having different types defined runtime) is to use an other mechanism, like std::variant.

please explain this-> in c++ [duplicate]

This question already has answers here:
What is the 'this' pointer?
(8 answers)
Closed 5 years ago.
so I saw this syntax
this->
used in a c++ tutorial on udemy but it was not explained to me as to what exactly why I would use this in programming. Can anyone provide an example program or proper example code that shows what this does? Please explain the logic behind it. Please don't say Google it. I know it has something to do with pointers and memory. and what not I guess another thing I am looking for is an explanation a five year old would understand or broken down enough for easy comprehension.
this keyword is used to reference current instance of given class, for example:
class A {
public:
void setName(std::string name) {
// if you would use name variable directly it
// will refer to the function parameter,
//hence to refer the field of the class you need to use this
this->name = name;
}
private:
std::string namel
}

Does Python have a pre-existing class called 'object'? [duplicate]

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.

Package access level [duplicate]

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?

C++ Unnamed Classes [duplicate]

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.