-
2 votesanswersviews
为二叉搜索树创建新节点
对于一个学校项目,我试图创建一个二叉搜索树,同时我们应该学习如何在课堂上使用“友谊” . 我在编译时得到的错误是:[为了清楚起见,我在代码中放置了错误来源于错误](请记住,我不允许在BST类中嵌套Node,它们都应该位于单独的文件和类中这个编程任务的缘故) BST.cpp: In member function `void BST::insert(std::string, std::string)... -
0 votesanswersviews
gcc:g官僚与模板模板朋友
在 Headers view.h中: template<class S, template<typename> class V> void Operate(S c, const V<S>& vx); template<class T, template<typename> class U> class ViewBase { ... -
5 votesanswersviews
在IOS 9中游戏中心多人游戏好友被打破了吗?
我创建了一个以编程方式使用实时多人游戏的游戏 . 它最初的目标是针对IOS 8设备 . 最近在迁移到IOS 9后,Game Center引发了很多问题 . 我无法解决的主要问题是在多人游戏中邀请朋友(用于测试) . 从IOS 8到IOS 8.自动匹配工作和朋友邀请工作但是从IOS 9到IOS 9.自动匹配工作和朋友邀请不再起作用 . 如果您有任何人设法让IOS 9上的Game Center邀请工作... -
2 votesanswersviews
朋友模板重载运算符<<:未解析的外部符号
我遇到了错误的问题 错误LNK2019未解析的外部符号“class std :: basic_ostream>&__ cdecl cop4530 :: operator <<(class std :: basic_ostream>&,class rob :: Stack const&)”(?? 6rob @@ YAAAV?$ basic_ostream @ DU?$ ch... -
-1 votesanswersviews
在ostream重载朋友功能中使用向量
我有一个名为“KeyedCollection”的模板类,它包含将数据插入向量以及流出数据的函数 . 向量是私有成员函数 . 我似乎无法弄清楚如何在我的重载ostream friend函数中使用此向量中的信息 . 注意:我不能改变类的一般结构和函数参数,它们必须保持原样 . 我列出了所有类以供参考,但有问题的函数是最后一个 . #include "stdafx.h" #inclu... -
2 votesanswersviews
如何从另一个派生类访问数据类的私有成员变量,该派生类的父类是数据类的友元类?
我有三个班: 数据持有者类CDataHolder,它使用Pimpl模式 class CDataHolder { public: // ... private: friend class CBase; struct PImpl; PImpl* iPimpl; }; 一个基类CBase,需要访问CDataHolder中的iPImpl成员,因此它是CDataHolder的友元类 class... -
7 votesanswersviews
如果类在命名空间下,则Friend函数无法访问私有函数
我在命名空间中有一个类,该类包含一个私有函数 . 并且有一个全球功能 . 我希望这个全局函数成为我的类的朋友,它位于命名空间内 . 但是当我把它作为朋友时,编译器认为该函数不是全局的,而是在该命名空间本身内部 . 因此,如果我尝试使用全局函数访问私有成员函数,它就不起作用,而如果我在该命名空间中定义一个具有相同名称的函数,它就可以工作 . 以下是您可以看到的代码 . #include <io... -
3 votesanswersviews
为什么我不能在一个属于另一个类的私有成员的类中声明一个朋友?
给出以下代码: class Screen; class WindowMgr { WindowMgr& relocateScreen( int r, int c, Screen& s); }; class Screen { friend WindowMgr& WindowMgr::relocateScreen( int r, int c, Screen&a... -
1 votesanswersviews
和一个 class 交朋友
我正在尝试与一个类成为朋友,以便它能够到达它的私有构造函数 . 在some_file.h中 class B; namespace some_name { class A { public: A() {} private: A (int x) {} friend class ::B; }; } 在other_file.h中 #include "s... -
1 votesanswersviews
无法访问朋友类的私人会员
有人会介意帮我解决C链接/编码难题吗? 我有一个类Shape . Shape需要使用类Center的私有数据成员,x和y坐标 . 我宣布朋友类Shape;然后在Shape.h中#include“center.h” . 在Shape.cpp中,我定义了我的ostream&operator <<(ostream&ostr,const Center&c)函数,它使用c.xCord; c.y... -
4 votesanswersviews
成员功能, class 的朋友
我一直在尝试编写一个代码来实现一个成员函数,该函数可以通过将其声明为类中的朋友来访问类的私有数据 . 但我的代码失败了,我似乎无法弄清楚它有什么问题: #include <iostream> using namespace std; class A; class B { private: int b; // This is to be accessed ... -
1 votesanswersviews
friend方法的参数列表中的不同模板特化
我正在尝试创建一个方法,该方法采用类模板的两个(不同)特化实例,并在编译时返回从模板特化推导出的类型的值 . 到目前为止我所拥有的是(在极少数情况下) #include <iostream> #include <utility> template<typename T> class box { protected: T value; public: ... -
0 votesanswersviews
模板类的模板操作员朋友,带有enable_if
我如何使用enable_if作为模板化类的朋友制作模板化运算符? 这是我的问题的一个例子: #include <type_traits> template<typename CHAR_TYPE> class BasicString; template<typename CHAR_TYPE, typename OTHER_CHAR_TYPE, typenam... -
2 votesanswersviews
Visual Studio 2010中的朋友模板类和Lambda函数
我在VS2010中遇到了编译错误,我不知道它是否应该被视为编译器错误: 我尽可能地简化了场景:模板类被声明为某个类的朋友,并尝试访问lambda函数内的朋友的私有成员 . 这是代码: class Foo { template<typename T> friend class Bar; int priv; }; template<typename T> cl... -
1 votesanswersviews
将模板函数声明为朋友
我有这样一个全局函数: namespace X { namespace Y { template <R, ...T> R foo(T&&... args) { R r(args...); return r; } } } 然后在另一个类 A 中,我想将此函数 foo 声明为 A 的朋友 . 所以我做了: class A { template <R,... -
0 votesanswersviews
如何通过friend关键字声明在类中声明的非成员函数的友元函数
我在以下代码中有两个关于朋友声明的问题 . (1)我宣布了一个朋友的功能 . 该程序看起来很有效,但我收到了编译器的警告 . 原始函数是由person声明的类中定义的非成员函数 . 我需要照顾它吗?或者我有问题吗? (2)如果可能的话,我想声明与拥有非成员函数的模板类函数的友谊 . 我试图与 class 宣布朋友船,但失败了 . 请给我解决方案或建议 . 非常感谢你 . #include <... -
8 votesanswersviews
模板类朋友操作员成员函数
我正在尝试在模板化的类中获取一个朋友函数来编译,但错误消息和警告我不明白 . 我已经证明了这个问题 . 我得到的错误是: prog.cpp:8:57:错误:非类,非可变部分特化C运算符(const B&lhs,const C&rhs); prog.cpp:15:59:警告:朋友声明'C运算符(const B&,const C&)'声明一个非模板函数[-Wnon-template-friend]朋... -
1 votesanswersviews
ostream专业模板类的朋友功能
template <> class test<int> { int y; public: test(int k) : y(k) {} friend ofstream& operator<< <test<int>> (ofstream& os, const test<in... -
1 votesanswersviews
问题与c中的朋友功能有关
我在 an h file 中使用了一些友元函数定义了以下类: #include <iostream> #include <math.h> namespace mtm { static bool compareIsBigger(double a, double b) { const double EPSILON = 1e-10; return fabs(a ... -
1 votesanswersviews
如何使用友元函数重载operator ==外部模板类?
我正在尝试编写一个重载 operator== 的模板类 . 我知道如何在课堂上学习它: template <typename T> class Point { private: T x; public: Point(T X) : x(X) {} bool operator== (Point &cP... -
2 votesanswersviews
在类模板中可见的朋友函数名称
请考虑以下示例: template <typename T> class C { public: friend void f() {} friend void f(C<T>) {} }; C<int> c; void g(C<int>* p) { f(); f(*p); } 使用GC... -
9 votesanswersviews
有 class 的朋友但无法访问私人会员
朋友功能应该能够访问类私有成员吗?那我在这里做错了什么?我已将我的.h文件包含在操作符<<我打算与 class 成为朋友 . #include <iostream> using namespace std; class fun { private: int a; int b; int c; public: fun(int a, int ... -
193 votesanswersviews
为什么C#不提供C风格'friend'关键字? [关闭]
C++ friend keyword允许 class A 将 class B 指定为其朋友 . 这允许 Class B 访问 class A 的 private / protected 成员 . 我从来没有读过任何关于为什么它被排除在C#(和VB.NET)之外的东西 . 对此earlier StackOverflow question的大多数答案似乎都说它是C的有用部分,并且有充分的理由使用它... -
1 votesanswersviews
C友比较一个类模板的两个实例
我正在尝试编写一个类模板,该模板在两个具有不同模板类型的实例之间提供比较运算符 . 通常情况下,该运营商是非会员朋友 . 我想要实现的一个简化示例如下所示 . template<typename T> class Wrapper { // Base type, which must have a val() method to allow comparison T t_; pu... -
8 votesanswersviews
类模板的朋友功能
我有一个类模板 Foo<T> . 我想实现一个非成员函数 Bar ,它需要两个 Foo 并返回一个 Foo . 我希望 Bar 成为非成员,因为调用者编写 Bar(f1, f2) 比 f1.Bar(f2) 更自然 . 我也希望 Bar 是 inline ,因为计算是微不足道的 . template <typename T> inline Foo<T> Bar... -
3 votesanswersviews
专业模板类的朋友(C)
#include <iostream> using namespace std; template <typename T> class test { T y; public: test(T k) : y(k) {} friend int a(T& x); }; template <typename T> int a(T&am... -
11 votesanswersviews
C友功能无法访问私人会员
这应该是一个包含一堆运算符和函数的字符串类,包括两个友元函数 . 这两个对我来说有些麻烦,因为编译器说他们无法访问私有成员 . 这是我的string.h: #include <iostream> #ifndef STR_H #define STR_H namespace MyStr { class Str { private: unsigned int length; ... -
1 votesanswersviews
C:制作模板operator =让朋友超载
所以我有一个模板化的vektor课程 template<t> class vektor { ... } 我希望能够写作 vektor<int> x; vektor<float> y; ... y = x; 所以我修改了课程 template<t> class vektor { template<typename U> ... -
4 votesanswersviews
模板类的模板友元函数
我有以下模板类和模板函数,它打算访问类的私有数据成员: #include <iostream> template<class T> class MyVar { int x; }; template<class T> void printVar(const MyVar<T>& var) { std::cout <<... -
6 votesanswersviews
C中的朋友和模板
我的C代码示例中存在一个大问题 . 'friend'和'template'有问题 . Error Messages:Matrix.h:26:79:警告: friend declaration'std :: ostream&matrixClass :: operator <<(std :: ostream&,const matrixClass :: Matrix&)'声明一个非模板函...