friend

    -2熱度

    1回答

    考慮以下一塊程序: class cls { int vi; public: cls(int v=37) { vi=v; } friend int& f(cls); }; int& f(cls c) { return c.vi; } int main() { const cls d(15);

    3熱度

    1回答

    可以說我有一個文件 //的Xh(第一文件) #include <iostream> class X{ int x; public: X(int i); void print_me(); }; // X.cpp(第二文件) #include "X.h" X::X(int i){x = i} void X::print_me(){std::cout<< x

    1熱度

    1回答

    我試圖指定一個類成員函數作爲另一個類的朋友, 但它只給我的訪問權限,而不是受保護或私人成員的公共成員。它的免費功能工作正常。 Visual Studio中的錯誤: member "Class1::protected_int" (declared at line 9) is inaccessible member "Class1::private_int" (declared at line 11

    3熱度

    3回答

    從李普曼等人C++引物第5版,部分16.1.2: //forward declarations needed for friend declarations in Blob template <typename> class BlobPtr; template <typename> class Blob; template <typename T> bool operator==(const

    0熱度

    1回答

    我有一個C++中的基類,它有一些受保護的成員變量(儘管我認爲它在這種情況下是受保護的而不是私有的)。 我有一個從這個基類派生的派生類。其中有一個公共函數,它創建基類的一個對象並返回該對象。然而,在這個函數中,我需要能夠將受保護的成員變量設置爲特殊狀態。 實施例: class Base { protected: int b_value; }; class Derived : pu

    6熱度

    2回答

    這是我的代碼的一個mcve :(如果有關係,Options_proxy和Options有合適的表示)。我知道這是一個從簡單的還有差距,但不能把它簡化多,同時仍出現該錯誤: template <class Impl> struct Options_proxy : Impl { using Flag = typename Impl::Flag; friend constexpr

    0熱度

    2回答

    以下代碼不起作用,因爲t成員函數無法訪問其參數對象的屬性。 如何聲明模板類A的模板方法t作爲A的朋友函數? 對於沒有模板的代碼,不需要聲明朋友。 代碼: template <typename T> class A{ protected: T a; public: A(int i){ a = i; } templat

    0熱度

    2回答

    如何方便地將很多模板函數聲明爲模板類的朋友函數? 例子: template <typename T> void funct1(MyClass<T> & A); //1.forward declaration. template <typename T> class MyClass{ protected: T a; friend funct1(MyClass<T

    4熱度

    3回答

    類A是類B的唯一實例化程序和實例的容器。 因此,將B類的構造函數設爲private並且僅在類B中聲明並在類A中定義的朋友函數來調用它似乎是個好主意。 文件阿(編輯:在B類中包括定義枚舉) #ifndef A_H #define A_H #include "B.h" using namespace std; class A { public: A(); share

    -1熱度

    1回答

    好吧,這裏是我的問題,我想了解在C++中使用朋友的一個工作示例,以供參考。我把所有的東西放在不同的類中,它們通過.h文件等相互連接(我認爲無論如何)。有人可以告訴我我要出錯哪裏嗎?因爲我不斷收到編譯器錯誤,我不明白它的意思。 是的我已經研究了在線的C:xxxx錯誤,但是我無法將問題鏈接到我得到的代碼......這顯然是錯誤的!只需要在正確的方向推動/更好地理解C++ ...謝謝! //First