oop

C++ virtual method not called as expected

拜拜、爱过 提交于 2021-02-11 04:21:17
问题 I'm fiddling around with proper overriding of virtual methods. I chain some constructors and in the base class constructor I call a virtual method. Call chain should be as followed: B(p)->A(p)->B.foo(p) Call chain is in C++: B(p)->A(p)->A.foo(p) Call chain is in C#: B(p)->A(p)->B.foo(p) So in other words, in C# behaviour is like expected, in C++ it isn't. C++ Code: #include <cstdio> class A { public: A(); A(int); virtual void foo(int s); }; class B : public A { public: B(); B(int s) : A(s) {}

How static fields are referenced through objects? [duplicate]

只谈情不闲聊 提交于 2021-02-10 23:24:00
问题 This question already has answers here : Accessing a static variable via an object reference in Java (6 answers) What is the proper way of accessing static fields in Java? (6 answers) Closed 2 years ago . I understand what static is but I can't find information how are the static fields referenced through the objects. Let's imagine that we have two classes: class Foo { static int statValue = 10; } class Bar { public static void main(String[] args) { Foo foo1 = new Foo(); int valFromObject =

How static fields are referenced through objects? [duplicate]

不打扰是莪最后的温柔 提交于 2021-02-10 23:23:19
问题 This question already has answers here : Accessing a static variable via an object reference in Java (6 answers) What is the proper way of accessing static fields in Java? (6 answers) Closed 2 years ago . I understand what static is but I can't find information how are the static fields referenced through the objects. Let's imagine that we have two classes: class Foo { static int statValue = 10; } class Bar { public static void main(String[] args) { Foo foo1 = new Foo(); int valFromObject =

Uncaught Error: Call to a member function prepare() on null error [duplicate]

荒凉一梦 提交于 2021-02-10 16:11:58
问题 This question already has an answer here : Fatal error Call to a member function prepare() on null (1 answer) Closed 3 years ago . I know there were a lot of answers related to this error, but I still don't know how to solve it... I'm trying to make the database connection, which would connect to the database and insert user's entered values in it and i got this error. I've created 2 files (with different classes): Here is a connection file: <?php class Connection { // Setting Database Source

Uncaught Error: Call to a member function prepare() on null error [duplicate]

天大地大妈咪最大 提交于 2021-02-10 16:10:31
问题 This question already has an answer here : Fatal error Call to a member function prepare() on null (1 answer) Closed 3 years ago . I know there were a lot of answers related to this error, but I still don't know how to solve it... I'm trying to make the database connection, which would connect to the database and insert user's entered values in it and i got this error. I've created 2 files (with different classes): Here is a connection file: <?php class Connection { // Setting Database Source

Call static methods when using default

僤鯓⒐⒋嵵緔 提交于 2021-02-10 15:41:02
问题 When using ES6 modules and export default class how is it possible to call a static method from another method within the same class? My question refers specifically to when the class is marked as default (unlike es6 call static methods) The below example illustrates how it is possible to call the static method from a non-static method when not using default, i.e. Test.staticMethod() ? export default class { static staticMethod(){ alert('static'); } nonStaticMethod(){ // will not work because

Creating a vector in class then using class object in function not working

独自空忆成欢 提交于 2021-02-10 12:53:27
问题 I have a class Employees . I'm trying to make the user insert and delete an employee but it's not working. The size of the vectors should be 500. class Employees{ public: int maxx = 500; vector<string> Surname; vector<string> FirstName; vector<string> birthdate; int vacation[500]; public: Employees() : Surname(500) {} }; This is the function that inserts, but printing elements of the vectors is not working at all: void Process(Employees ZZ){ string dateyear; string datemonth; string dateday;

How to check if string exists in Enum of strings?

给你一囗甜甜゛ 提交于 2021-02-10 07:10:49
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in

How to check if string exists in Enum of strings?

风格不统一 提交于 2021-02-10 07:10:15
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in

How to check if string exists in Enum of strings?

倖福魔咒の 提交于 2021-02-10 07:05:28
问题 I have created the following Enum: from enum import Enum class Action(str, Enum): NEW_CUSTOMER = "new_customer" LOGIN = "login" BLOCK = "block" I have inherited from str , too, so that I can do things such as: action = "new_customer" ... if action == Action.NEW_CUSTOMER: ... I would now like to be able to check if a string is in this Enum, such as: if "new_customer" in Action: .... I have tried adding the following method to the class: def __contains__(self, item): return item in [i for i in