Can't Understand C++ Function Declaration [duplicate] - c++

This question already has answers here:
Why is a pure virtual function initialized by 0?
(11 answers)
Virtual/pure virtual explained
(12 answers)
Closed 3 years ago.
I was reading through the source code of a program written in C++ when I came across a few function declarations like this:
virtual bool _Open(LPCTSTR aFileSpec, DWORD &aFlags) = 0;
Why is this declared function being set equal to zero?
Additional Question: (Edit)
What would a statement like this mean?
virtual __int64 _Length() const = 0;
What other keywords could replace const, and what would they mean?

This is a pure virtual function: https://en.cppreference.com/w/cpp/language/abstract_class
Deriving non-abstract classes are expected to implement it.

Related

I can't understand this type of function pointer [duplicate]

This question already has answers here:
Obtaining a function pointer to a non static member function
(2 answers)
Function pointer to member function
(8 answers)
How do pointers to member functions work?
(2 answers)
Closed 7 months ago.
I'm starting to study Unreal Engine and I saw this code:
UCLASS()
class AMyPlayerController : public APlayerController
{
GENERATED_BODY()
void SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("Fire", IE_Pressed, this, &AMyPlayerController::HandleFireInputEvent);
InputComponent->BindAxis("Horizontal", this, &AMyPlayerController::HandleHorizontalAxisInputEvent);
InputComponent->BindAxis("Vertical", this, &AMyPlayerController::HandleVerticalAxisInputEvent);
}
void HandleFireInputEvent();
void HandleHorizontalAxisInputEvent(float Value);
void HandleVerticalAxisInputEvent(float Value);
};
I've understood everything but this line:
InputComponent->BindAction("Fire", IE_Pressed, this, &AMyPlayerController::HandleFireInputEvent);
What is the fourth parameter? I'm new to C++ but I've studied the basics of C while in college. What I can't understand is the "::". I know that the "&" means that the parameter is a pointer to the memory address of MyPlayerController, but what about the double points?
I assume that I'm passing as fourth parameter the HandleFireInputEvent function of the MyPlayerController class but I would like to know more about you.
Many thanks.
The fourth argument is the address of a class member function. And that function has a name within the class scope, just as when you have to implement a class member.

Does adding const affect overriding [duplicate]

This question already has answers here:
Why doesn't a const method override a non-const method in C++?
(6 answers)
virtual function const vs virtual function non-const
(3 answers)
Top-level const doesn't influence a function signature
(7 answers)
const qualifier disappears from pure virtual function [duplicate]
(1 answer)
Closed 2 years ago.
Suppose I have a method1 in the parent class and I want to override it in a subclass. Does adding const affect the overriding? For example,
int Subclass::method1(const int a)const {...}
Does this override
int Parentclass::method1(int a) {...}
correctly?

Is there a technical reason for not allowing nested function definitions? [duplicate]

This question already has answers here:
Why can't I define a function inside another function?
(11 answers)
Can we have functions inside functions in C++?
(13 answers)
Nested function in C
(9 answers)
Closed 3 years ago.
Why C++ does not allow something like:
int foo(int x) {
void bar(int x) { return x*x;}
return bar(x);
}
Disclaimer: I am not asking for the rationale for disallowing it. We can define classes inside functions, in particular functors, and since C++11 lambdas, so actually I do not see the need for it.
However, I wonder if there is some technical limitation/problem that would prevent to allow it. Would it create ambiguities syntax-wise? Other problems that I dont see? Or is the answer perhaps simply: It is not allowed because there is no need for it?

Are there any differences in calling function using this and not using this? [duplicate]

This question already has answers here:
Is there any reason to use this->
(16 answers)
Use of "this" keyword in C++ [duplicate]
(6 answers)
Closed 8 years ago.
Class::Class() {
this->func();
}
and
Class::Class() {
func();
}
Are there any differences between these two ways of calling a function?
Yes, this->var ensures you're working with instance variable - which may be useful when your instance variables may be shadowed inside a block.

Implementation of pure virtual method with/without virtual? [duplicate]

This question already has answers here:
C++ "virtual" keyword for functions in derived classes. Is it necessary?
(9 answers)
Closed 8 years ago.
If I have an AbstractClass with a "virtual void Method()=0". What is the difference if a DerivedClass defines the implementation as "virtual void Method() { }" or simply "void Method() { }" ?
There is no difference. It's just for clarity.
Any method defined as virtual in a base class, is also virtual in the classes which inherit from it, regardless whether it's declared like that or not.