cost 230 ms
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 不存在默認構造函數”。 我試過這個 同樣的事情發生了。 請幫我。 克服這種情況。 為什么我不能繼承構造函數 ...

有什么方法可以使這個 C++ 程序無錯誤,或者我必須刪除繼承的 class 中聲明的 x 之一

[英]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 ...

如何處理相同方法的多個 inheritance 或 CRTP static 多態性的鑽石問題?

[英]How to handle multiple inheritance of same methods or diamond problem with CRTP static polymorphism?

我想用 CRTP 靜態實現多態性。 我想創建幾個提供功能的基類。 然而,功能可以重疊。 但是,如果它們重疊,它們是相同的。 假設我有 Boxer和Chess Player都提供walk 。 walk的兩個定義是相同的。 順便說一句,我可以(並且可能我應該)重寫上面的代碼以避免重復walk的代碼 ...

讓子類從兩個不同的父類繼承特定屬性?

[英]Make a child class inherit specific attributes from two different parent classes?

我對 Diamond 繼承練習有疑問。 我有一個基類 A。這是它的構造函數: 然后,我有兩個父類 B 和 C。這是它們的構造函數: 最后,我有一個孩子班。 這是它的構造函數: D 類從 B 類和 C 類繼承。B 和 C 類都從 A 類繼承。我做了這樣的事情: 正如在 D 類的構造 ...

對象構造為一個基類,方法計算為另一個基類(菱形繼承和代碼冗余)

[英]object constructed as one base class, method calculated as other base class (diamond inheritance and code redundancy)

我有一個通過虛擬繼承解決的 C++ 中的菱形繼承方案。 基類general有兩個屬性和一些使用它們的方法。 specialrestriction限制是具有兩個屬性相等的特殊限制的general 。 特殊規則用特殊規則稍微修改了specialrule somemethod() 。 最后 ...

在這種情況下,您能否為多個 inheritance 建議一個好的替代方案?

[英]Can you suggest an good alternative for multiple inheritance in this case?

總結:下面的案例涉及使用多個 inheritance 來繼承擴展接口和基本接口的實現。 我使用虛擬多個 inheritance 來建立以下系統: 我有一個抽象接口層次結構: 正如預期的那樣,特定接口在派生自 ICommon 的通用功能之上添加了功能。 我也有實現接口的類: CommonImp(實 ...

我在父 class 中有一個變量 b,當我嘗試從 sum3 class 訪問變量 b 時,它顯示不明確的 b 錯誤

[英]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++ 成員和 vtable 順序在菱形(多個)虛擬 inheritance

[英]C++ Member and vtable order in diamond (multiple) virtual inheritance

我想知道菱形虛擬 inheritance 上 C++ 中成員變量和 vtable 指針的順序。 考慮下面的 inheritance: 我想知道 class Derived3 的memory布局。 我在網上查看了以下鏈接: c++ 數據 alignment /會員訂單 & inherita ...

如何:使用不同的 arguments 安全地調用超級構造函數

[英]How to: safely call super constructors with different arguments

我已經看到super().__init__(*args)用於安全地調用超級構造函數(以一種不會失敗菱形繼承的方式)。 但是我找不到以這種方式調用具有不同 arguments 的不同超級構造函數的方法。 這是一個說明問題的示例。from typing import TypeVar, Generic ...

我的 inheritance 和有問題的“鑽石繼承”一樣嗎

[英]Is my inheritance the same as the problematic "diamond inheritance"

我有多個虛擬基類,它們為我的實現類創建接口。 然而,我希望他們都能夠序列化和反序列化自己。 這導致以下 ABC inheritance: 假設我有 class A ,它允許對 class 進行序列化和反序列化。 我有一個 class B,它添加了一些虛擬調用,但還必須能夠處理它自己的序列化操作: 現 ...

解決精益中的“鑽石繼承”class

[英]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++:鑽石的派生類調用默認構造函數

[英]Diamond Problem C++: Derived class of diamond calls default constructor

因此,作為我程序的公共 API 的一部分,我公開了類 D,以便用戶從類 D 繼承以創建他們自己的類。 然而,D 類是致命鑽石的一角,我遇到了一個問題,即用戶的類正在調用 A 類的默認構造函數,而不是所需的參數化構造函數。 在下面的代碼中,類 E 是一個干凈的 API,但是調用了錯誤的 A 構造 ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM