virtual-functions Questions
9
Solved
I know virtual methods from PHP or Java.
How can they be implemented in Python?
Or have I to define an empty method in an abstract class and override it?
Newfoundland asked 17/1, 2011 at 14:14
3
Solved
I know virtual inheritance is covered here before and before asking this question, I went through the detail of the virtual inheritance and went through the details of a similar problem like the fo...
Tillage asked 3/6, 2014 at 2:28
4
Solved
Can virtual functions like X::f() in the following code
struct X
{
constexpr virtual int f() const
{
return 0;
}
};
be constexpr?
Eliathas asked 16/1, 2016 at 14:34
3
Solved
This is my code snippet:
class Base {
public:
Base() {
foo();
bind();
}
virtual void foo() {
std::cout << "base foo\n";
}
void bind() {
fn = std::bind(&Base::foo, t...
Sutton asked 25/9, 2023 at 14:10
1
Solved
What is the difference in between declaring a new (non override) member function virtual final versus just non-virtual?
I'm guessing a virtual final member function (that does not override anything...
Dedicated asked 20/9, 2023 at 13:51
28
Solved
From what I've read, virtual functions are functions in the base class that you can override in its derived classes.
But earlier, when learning about basic inheritance, I was able to override base ...
Insoluble asked 6/3, 2010 at 7:10
3
Solved
Suppose we have an abstract Base class that is inherited:
class Base
{
protected:
Base() {}
virtual ~Base() {}
virtual void on_event_foo(int) {}
virtual void on_event_bar(int) {}
};
struct C...
Hoshi asked 2/6, 2016 at 9:42
2
Solved
I've got classes called "Base" and "Derived".
struct Base {
Base() = default;
virtual ~Base() = default;
Base(const Base&) = delete;
Base& operator=(const Base&)...
Gendron asked 1/2, 2023 at 14:34
15
Solved
Suppose I have two C++ classes:
class A
{
public:
A() { fn(); }
virtual void fn() { _n = 1; }
int getn() { return _n; }
protected:
int _n;
};
class B : public A
{
public:
B() : A() {}
vi...
Saintly asked 7/6, 2009 at 15:46
11
Solved
Wikipedia has the following example on the C++11 final modifier:
struct Base2 {
virtual void f() final;
};
struct Derived2 : Base2 {
void f(); // ill-formed because the virtual function Base2::...
Headrail asked 28/7, 2012 at 20:27
2
I am an accomplished C programmer, and I have written an assembler and VM in C (https://github.com/chucktilbury/assembler (mostly working but not complete)) and I am thinking of porting it to C++ s...
Launceston asked 5/9, 2022 at 18:10
8
Solved
I think I understand the concept of virtual methods and vtables, but I don't understand why there is a difference between passing the object as a pointer(or reference) and passing it by value (whic...
Ignace asked 28/4, 2011 at 15:28
10
Solved
Unlike Java, why does C# treat methods as non-virtual functions by default? Is it more likely to be a performance issue rather than other possible outcomes?
I am reminded of reading a paragraph fr...
Bathroom asked 2/5, 2009 at 14:28
6
Solved
Scott said on Effective C++, 3rd Edition, pg. 43 that to make an abstract class, we just need to give it a pure virtual destructor:
class AWOV { // AWOV = "Abstract w/o Virtuals"
public:
virtual ...
Tomi asked 16/10, 2012 at 15:52
15
I have heard that C++ class member function templates can't be virtual. Is this true?
If they can be virtual, what is an example of a scenario in which one would use such a function?
Chicalote asked 1/3, 2010 at 6:26
6
Solved
As far as I understand, the introduction of override keyword in C++11 is nothing more than a check to make sure that the function being implemented is the overrideing of a virtual function in the b...
Marlette asked 14/12, 2012 at 14:5
2
Solved
I executed the following code.
#include <iostream>
class Base
{
public:
virtual void func()
{
std::cout<<"Base func called"<<std::endl;
}
};
class Derived: public ...
Microbalance asked 1/9, 2021 at 20:0
10
Solved
I have a base class with a virtual function and I want to override that function in a derived class. Is there some way to make the compiler check if the function I declared in the derived class act...
Leolaleoline asked 30/1, 2009 at 23:8
23
Why does C++ not have a virtual constructor?
Stylize asked 9/4, 2009 at 8:46
27
Solved
What is the difference between an abstract method and a virtual method? In which cases is it recommended to use abstract or virtual methods? Which one is the best approach?
Dusen asked 24/12, 2008 at 14:11
3
Solved
For this code:
class B1{
public:
virtual void f1() {}
};
class D : public B1 {
public:
void f1() {}
};
int main () {
B1 *b1 = new B1();
D *d = new D();
return 0;
}
After compilation, t...
Dextrin asked 19/4, 2011 at 7:8
6
Coming form a C++/Java/C# background I was expecting to see virtual methods in Swift, however reading the swift documentation I see no mention of virtual methods.
What am I missing?
Due to large n...
Severe asked 3/6, 2014 at 11:29
8
Solved
Say I have classes Foo and Bar set up like this:
class Foo
{
public:
int x;
virtual void printStuff()
{
std::cout << x << std::endl;
}
};
class Bar : public Foo
{
public:
int y...
Idle asked 23/3, 2009 at 6:17
2
Solved
At work, I ran into a situation where the best type to describe the result returned from a function would be std::variant<uint64_t, uint64_t> - of course, this isn't valid C++, because you ca...
Tolerable asked 11/11, 2020 at 1:23
3
From this implementing operator== when using inheritance question, I see people say that operator== should not be made virtual (the accepted answer even says "operators cannot be virtual"...
Smoothtongued asked 29/10, 2020 at 7:27
1 Next >
© 2022 - 2024 — McMap. All rights reserved.