- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我偶然发现了一个在我看来非常有趣的问题。我不是要解决这个问题,只是建议如何继续我的代码,我想知道派生类是否继承了基类的 friend 。
问题是:
Class matrix, friend of class array is the base class for the class diagonal_matrix. The derived class must contain a parameterized constructor through which to highlight the transmission of parameters towards the constructor from the base class, destructor and a method to check if the matrix is square and diagonal ( all elements other than the ones from the principal diagonal are equal to zero). Illustrate the concept of virtual function (pure if it's more natural in implementation).
这是我到目前为止写的(今天关于如何继续不是很有创意):
#include <iostream>
using namespace std;
class arry
{
private:
int *vec;
int n;
public:
int i,nrelem;
arry(){};
~arry();
void readArray(int);
};
arry::~arry()
{
n=0;
delete [] vec;
}
void arry::readArray(int elem)
{
n=elem;
vec=new int[n];
for(i=1;i<=elem;i++)
{
cout<<"vec["<<i<<"]=";
cin>>vec[i];
}
}
class matrix
{
public:
friend class arry;
matrix(int , int);
~matrix();
};
int main()
{
return 0;
}
最佳答案
friend of class array is the base class for the class diagonal_matrix
类 array
没有 friend 。 array
类是 matrix
类的 friend ,因为它是 matrix
声明的
class matrix
{
public:
friend class arry; // this is my friend
matrix(int , int);
~matrix();
};
你要求
advices on how to continue with my code
从在 array
类中声明友元开始。
and I'd like to know if derived classes inherit the friends of the base class
如果基类将 class A
声明为友元,则它不是派生类的友元,除非该派生类也将 class A
声明为友元。
C++ 标准 n3337 § 11.3/10 friend
Friendship is neither inherited nor transitive.
关于c++ - 类(class)传承与友元项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23920931/
我正在使用 Eloquent/Laravel 设计一个数据库,我想知道以下是否是最佳实践。 对于“汽车”表,某些列特定于汽车类型(负载箱尺寸),而某些列则适用于所有汽车(颜色)。 如果我有一张表,其中
难道不能从 boost::variant 继承并使用结果类作为选择运算符的结果吗? struct jass_statement_node { }; typedef boost::variant , b
我是一名优秀的程序员,十分优秀!