[英]C++, child with both parents having a same ancestor
我現在遇到 C++ 類和 inheritance 的問題... 假設我們有 每當我創建D時,它都會調用B的構造函數和C的構造函數,這會導致A的多個實例。 然后編譯器說它不知道應該調用哪個“函數”,是來自B的那個還是來自C的那個。 我想知道如何只調用A構造函數一次,然后用它來構建B和C 。 我已經嘗試 ...
[英]C++, child with both parents having a same ancestor
我現在遇到 C++ 類和 inheritance 的問題... 假設我們有 每當我創建D時,它都會調用B的構造函數和C的構造函數,這會導致A的多個實例。 然后編譯器說它不知道應該調用哪個“函數”,是來自B的那個還是來自C的那個。 我想知道如何只調用A構造函數一次,然后用它來構建B和C 。 我已經嘗試 ...
[英]constructor not Inheriting
我試圖從基類繼承一個 comstructor 到派生類,該派生類派生自基類的另一個派生類。 但在繼承基類構造函數后,它說“類 Waiverstudents 不存在默認構造函數”。 我試過這個 同樣的事情發生了。 請幫我。 克服這種情況。 為什么我不能繼承構造函數 ...
[英]Is there any way to make this C++ program error free or I have to remove one of x declared in one the inherited class
Output錯誤:對成員“x”的請求不明確 Although I have used virtual class, still I am getting the above error.Do I have to remove One of the x declared in class B an ...
[英]How to handle multiple inheritance of same methods or diamond problem with CRTP static polymorphism?
我想用 CRTP 靜態實現多態性。 我想創建幾個提供功能的基類。 然而,功能可以重疊。 但是,如果它們重疊,它們是相同的。 假設我有 Boxer和Chess Player都提供walk 。 walk的兩個定義是相同的。 順便說一句,我可以(並且可能我應該)重寫上面的代碼以避免重復walk的代碼 ...
[英]It keeps telling me that this object has no len in leetcode 35. Search Insert Position
它一直給我這個錯誤你能告訴我為什么。 我找不到答案class Solution: def searchInsert(self, nums: List[int], target: int) -> int: x = len(List) for i in r ...
[英]Make a child class inherit specific attributes from two different parent classes?
我對 Diamond 繼承練習有疑問。 我有一個基類 A。這是它的構造函數: 然后,我有兩個父類 B 和 C。這是它們的構造函數: 最后,我有一個孩子班。 這是它的構造函數: D 類從 B 類和 C 類繼承。B 和 C 類都從 A 類繼承。我做了這樣的事情: 正如在 D 類的構造 ...
[英]What happens if a class implements two interfaces that extend the same base interface?
考慮 C# 中的以下接口: public interface IUpgradeable { public void Upgrade(); } public interface ISpeedUpgradeable : IUpgradeable { public int GetCur ...
[英]Selecting default implementation from indirectly inherited Interface not working
我有 4 個類看起來像這樣: 為什么我不能訪問來自擴展 Bar 的默認實現? ...
[英]object constructed as one base class, method calculated as other base class (diamond inheritance and code redundancy)
我有一個通過虛擬繼承解決的 C++ 中的菱形繼承方案。 基類general有兩個屬性和一些使用它們的方法。 specialrestriction限制是具有兩個屬性相等的特殊限制的general 。 特殊規則用特殊規則稍微修改了specialrule somemethod() 。 最后 ...
[英]Can you suggest an good alternative for multiple inheritance in this case?
總結:下面的案例涉及使用多個 inheritance 來繼承擴展接口和基本接口的實現。 我使用虛擬多個 inheritance 來建立以下系統: 我有一個抽象接口層次結構: 正如預期的那樣,特定接口在派生自 ICommon 的通用功能之上添加了功能。 我也有實現接口的類: CommonImp(實 ...
[英]removing duplicates in multiple inheritance(with diamond inheritance)
我正在嘗試解決 inheritance 問題,其中 class P繼承自N和O ,以及類N和O繼承自M 。 Headerclass M { public: M(); M(int aVal); int a; }; class N : virtual public ...
[英]I have a variable b in parent class and when i try to access variable b from sum3 class it shows ambiguous b error
我在父 class 中有一個變量 b ,當我嘗試從 sum3 class 訪問變量 b 時,它顯示了一個模棱兩可的 b 錯誤。 如果我從 inheritance 中刪除總和,它將給出“clas.cpp|25|error: 'int sum::b' is inaccessible in this co ...
[英]C++ Member and vtable order in diamond (multiple) virtual inheritance
我想知道菱形虛擬 inheritance 上 C++ 中成員變量和 vtable 指針的順序。 考慮下面的 inheritance: 我想知道 class Derived3 的memory布局。 我在網上查看了以下鏈接: c++ 數據 alignment /會員訂單 & inherita ...
[英]How to: safely call super constructors with different arguments
我已經看到super().__init__(*args)用於安全地調用超級構造函數(以一種不會失敗菱形繼承的方式)。 但是我找不到以這種方式調用具有不同 arguments 的不同超級構造函數的方法。 這是一個說明問題的示例。from typing import TypeVar, Generic ...
[英]Is my inheritance the same as the problematic "diamond inheritance"
我有多個虛擬基類,它們為我的實現類創建接口。 然而,我希望他們都能夠序列化和反序列化自己。 這導致以下 ABC inheritance: 假設我有 class A ,它允許對 class 進行序列化和反序列化。 我有一個 class B,它添加了一些虛擬調用,但還必須能夠處理它自己的序列化操作: 現 ...
[英]Resolving a "diamond inheritance" class in lean
對於精益,我有一個非常基本的循環結構。 我為岩漿構造了 class,為准群(抵消岩漿)構造了 class,為單位岩漿構造了 class。 從那里開始,一個循環就是一個既是准群又是單位岩漿的東西。 在 Haskell 這看起來像class Magma a where add :: a -> ...
[英]Heap Corruption Detected in diamond problem
我使用虛擬 inheritance 來解決鑽石問題。 代碼在調用基礎 class A 的析構函數后崩潰,並出現“檢測到堆損壞”錯誤: 有任何想法嗎? ...
[英]C++ Multipath Inheritance : Why the access using Base class scope is non-ambiguous?
我正在學習 C++,在學習虛擬繼承時,我遇到了以下疑問: 在線cout << dA::x; 它打印 5。這個調用不應該是模棱兩可的,如果不是為什么它會打印 5? ...
[英]Diamond Problem C++: Derived class of diamond calls default constructor
因此,作為我程序的公共 API 的一部分,我公開了類 D,以便用戶從類 D 繼承以創建他們自己的類。 然而,D 類是致命鑽石的一角,我遇到了一個問題,即用戶的類正在調用 A 類的默認構造函數,而不是所需的參數化構造函數。 在下面的代碼中,類 E 是一個干凈的 API,但是調用了錯誤的 A 構造 ...
[英]How to take values from different classes in diamond-inheritance
這是我的第一個鑽石繼承代碼。 在類 CI 上需要從類 B 中獲取 _points 的值和從類 C 中獲取 _energy 的值,但輸出是下一個: name class D Bill name class A another name energy class D 10 points cl ...