scriptlist=`ls $directory_/fallback_* 2> /dev/null`
Run Code Online (Sandbox Code Playgroud)
2>命令部分的目的究竟是什么?我省略了它并运行命令,它工作正常.
并且,如果ls的输出存储在/ dev/null文件中,那么变量scriptlist将包含什么.当我执行代码时,输出在变量中,文件中没有任何内容null.如果我们删除2,则输出是文件而不是变量.知道这行代码到底在做什么吗?
在我的代码中,我使用了三个类.请参阅以下实施:
class Medicine
{
int a;
}
class Pain:public Medicine
{
int b;
}
class Comb:public Pain
{
string salt,com;
}
Run Code Online (Sandbox Code Playgroud)
所有类都只有参数化构造函数.而call()像
call()
{
cout<<"You are in class the_name_of_the_class"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
我已经call()在所有这些中定义了一个具有相同名称的函数.(到现在为止,他们不被宣布为虚拟)
代码如下:
int main()
{
Pain *p[2];
p[0]= new Comb("Salt","Com",2,110);
p[1]= new Comb("SALT","COM",1,100);
p[0]->call();
delete p[0];
delete p[1];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:呼叫转到Pain的呼叫()
但是,如果我将Pain :: call()设为virtual(Medicine :: call()为real),则调用将转到Comb的call().没有任何问题!
但当我做Medicine *p[2]而不是Pain *p[2],发生以下错误
*** glibc detected *** ./a.out: free(): invalid pointer: 0x00000000022ed078 ***
======= Backtrace: …Run Code Online (Sandbox Code Playgroud)