inheritance

How to call a template super class's constructor from a template base class's constructor in c++?

与世无争的帅哥 提交于 2021-02-05 09:41:38
问题 I'm programming in c++ using sublimetext3. My program has a superclass called Array, and a subclass called IntArray. Both classes are template classes. Currently, I'm having trouble compiling the program. It keeps giving me an error in my IntArray.cpp file, specifically in my base class's constructor where I call and initialize the superclass's constructor with the parameter of the base class's constructor. I'm not sure how to call a superclass's template constructor from a subclass's

“Object” does not contain a definition for “name”

笑着哭i 提交于 2021-02-05 09:32:31
问题 I'm having an error message that tells me this: 'BankAccount.account' does not contain a definition for 'withdraw'. Here's my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BankAccounts { class account { protected string name; protected float balance; public account(string n, float b) { name = n; balance = b; } public void deposit(float amt) { balance -= amt; } public void display() { Console.WriteLine("Name: {0}. Balance: {1}.", name,

order of calling constructor in inheritance

你离开我真会死。 提交于 2021-02-05 08:46:34
问题 I am new to C++ programming language, i have a confusion about order of calling the constructor in inheritance. my question is even though the constructor and destructor are not inherited by derived class why the base class constructor will call when i create a derived class object. 回答1: The purpose of a constructor is to define how the data members should be initialised. Since a derived class inherits the data members from the base class, any constructor of the derived class must define not

C++ Base Class Function Overloading in a Subclass [duplicate]

萝らか妹 提交于 2021-02-05 08:34:48
问题 This question already has answers here : Why does an overridden function in the derived class hide other overloads of the base class? (4 answers) Closed 4 years ago . Given the following... #include <iostream> using namespace std; class BaseClass { public: void Func(float f) { cout << "BaseClass:Func() called!"; } }; class SubClass : public BaseClass { }; int main() { SubClass sub; sub.Func(1.1f); return 0; } This runs pretty much as one would expect, resulting in the following output...

C++ array of base class which has instances of derived classes stored in the elements of the array

℡╲_俬逩灬. 提交于 2021-02-05 07:48:08
问题 I am creating an application that allows a user to define dimensions for different shapes and returns the area to the user using the dimensions they specified. My base class is Shape. Derived classes are Triangle, Circle, Square and Rectangle. I have created an array of Shape in the hope of creating and storing instances of any of the derived classes in the array during runtime. Shape** shape = new Shape*[TOTAL_SHAPES]; shape[i] = new Circle(radius); I have managed this, however I am unable

C++ array of base class which has instances of derived classes stored in the elements of the array

雨燕双飞 提交于 2021-02-05 07:48:06
问题 I am creating an application that allows a user to define dimensions for different shapes and returns the area to the user using the dimensions they specified. My base class is Shape. Derived classes are Triangle, Circle, Square and Rectangle. I have created an array of Shape in the hope of creating and storing instances of any of the derived classes in the array during runtime. Shape** shape = new Shape*[TOTAL_SHAPES]; shape[i] = new Circle(radius); I have managed this, however I am unable

Extract subclass elements from List of parent class

China☆狼群 提交于 2021-02-05 07:48:05
问题 I currently have a list like so: List<Parent> parentList = new Arraylist<>; //Code inserts elements of subclassA and subclass B into parentList above now I want to extract the elements from parentList who are of type subclass A. I want to do the following but without errors: List<SubclassA> extractMe = new Arraylist<>; for (Parent parent: parentList){ if (parent.isSubclassA()){extractMe.add(parent);} } I am not sure how I can do this. I keep getting errors that I am adding what could be the

What is the difference let o1.prototype = Object.create(o2.prototype) and o1.prototype = o2.prototype? [duplicate]

和自甴很熟 提交于 2021-02-05 06:57:05
问题 This question already has answers here : Why wouldn't I use Child.prototype = Parent.Prototype rather than Child.prototype = new Parent(); for Javascript inheritance? (3 answers) Benefits of using `Object.create` for inheritance (4 answers) Closed 1 year ago . So I'm trying to understand the difference between o1.prototype = Object.create(o2.prototype) and o1.prototype = o2.prototype . According to the answer to this question, the former sets obj2.prototype to by the prototype for obj1

When to use abstract class as type

本小妞迷上赌 提交于 2021-02-05 06:56:06
问题 So while trying to understand abstract classes, there is still one thing I am confused on. When do you ever want to declare an object type of its abstract class. For example public abstract class GameObject { public abstract void draw(); public static void main(String[] args) { GameObject player = new Player(); Menu menu = new Menu(); } } public class Player extends GameObject { override public void draw() { // Something } } public class Menu extends GameObject { override public void draw() {

When to use abstract class as type

ⅰ亾dé卋堺 提交于 2021-02-05 06:56:05
问题 So while trying to understand abstract classes, there is still one thing I am confused on. When do you ever want to declare an object type of its abstract class. For example public abstract class GameObject { public abstract void draw(); public static void main(String[] args) { GameObject player = new Player(); Menu menu = new Menu(); } } public class Player extends GameObject { override public void draw() { // Something } } public class Menu extends GameObject { override public void draw() {