请告诉我In-core inode列表和磁盘inode列表之间的区别,参考Unix文件系统.
另外,请指点我可以获得更多信息的链接.
谢谢,LinuxPenseur
默认情况下,STDOUT是否无缓冲?如果不是,它的默认缓冲类型是什么
谢谢
我有两个shell脚本a.sh并b.sh在我的主目录中.在a.sh中我调用b.sh as
sh b.sh
Run Code Online (Sandbox Code Playgroud)
我也可以通过以下方式完成
. b.sh
Run Code Online (Sandbox Code Playgroud)
请告诉我调用之间的区别.
谢谢,LinuxPenseur
请考虑以下示例代码:
#include <iostream>
using namespace std;
class base
{
public:
base()
{
cout << "ctor in base class\n";
}
};
class derived1 : public base
{
public:
derived1()
{
cout <<"ctor in derived class\n";
}
};
int main()
{
derived1 d1obj;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题
在d1obj创建时,按照派生的顺序调用构造函数:首先调用基类构造函数,然后调用派生类构造函数.这是因为做的原因如下:In-order to construct the derived class object the base class object needs to be constructed first?
是否d1obj包含基类对象?
我还要补充一个问题
3)当创建d1obj时,控件首先到达基类构造函数然后转到派生类构造函数?或者它是相反的方式:它首先到达派生类构造函数,发现它有基类,所以控件转到基类中的构造函数?
请考虑以下示例代码:
#include <iostream>
using namespace std;
class core
{
public:
core(const core& obj)
{
cout << "core copy ctor called\n";
}
core()
{
cout << "core default ctor called\n";
}
};
class sample : public core
{
public:
sample()
{
cout << "sample default ctor called\n";
}
#if 0
sample(const sample& obj)
{
cout << "sample copy ctor called\n";
}
#endif
};
int main()
{
sample s1;
sample s2 = s1; //Line1
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Type1:未为类示例显式声明的复制构造函数
(Type1显示在上面的代码中.然后编译器隐式生成类sample的复制构造函数).Line1执行语句时,首先class …
c++ copy-constructor default-constructor implicit-declaration
请考虑以下示例代码.
#include <iostream>
using namespace std;
class base
{
public:
void func()
{
cout << "base::func()" << endl;
}
};
class derived : public base
{
public:
void func()
{
cout << "derived::func()" << endl;
}
};
void dummy(base *bptr)
{
derived *dptr = static_cast<derived*> (bptr);
dptr->func();
}
int main()
{
base bob1;
derived dob1;
dummy(&dob1); //Line1
dummy(&bob1); //Line2
}
Run Code Online (Sandbox Code Playgroud)
在Line1中,我将派生类对象的地址传递给函数dummy,该函数接受指向基类对象的指针.所以static_cast在功能上dummy是安全的.
在Line2中,我将基类对象的地址传递给函数.所以static_cast在功能上dummy是不安全的.
但是当我执行代码时,程序运行正常.我想,通过这个词not safe,程序应该在运行时崩溃.但没有发生崩溃.
这是我得到的输出.
derived::func()
derived::func()
Run Code Online (Sandbox Code Playgroud)
程序在运行时没有崩溃的原因是什么?
如果map在函数内部声明了STL ,是否需要在函数退出之前清除映射?如果没有清除,是否会导致内存泄漏?
我写了以下示例代码:
class MyClass {
static int a;
public:
MyClass ( int i ) : a ( i ) {
cout << " \n ctor called. a is : "<< a << " \n";
}
};
int MyClass::a = 1;
int main( ) {
MyClass my(2);
}
Run Code Online (Sandbox Code Playgroud)
我知道这会产生编译错误,因为静态数据成员不能在构造函数初始化列表中使用.
那么如何在每次创建类的对象时初始化静态数据成员?我希望从构造函数调用的静态成员函数可以做到这一点.这是唯一可能的方式吗?
请考虑以下示例代码:
File1.cpp
#include <iostream>
static int x = 6; // line 3
int main()
{
int x = 10; // line 7
{
extern int x; // line 9
x = x + 5;
std::cout << "x = " << x << "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
由于外部声明x,将访问静态变量x而不是自动变量x.但我得到以下编译器警告:
File1.cpp:5:警告:'x'已定义但未使用
即使有了这个警告,我也得到了预期的输出x = 11,即5增加到静态变量的值x.
为什么编译器会给出上述警告?我正在使用GCC版本g++ (GCC) 3.4.6
请考虑以下代码段:
function isUniform(myArray) {
myArray.forEach(function(element) {
if (element !== myArray[0]) {
return false;
}
});
return true;
}
Run Code Online (Sandbox Code Playgroud)
目的是该函数应该将数组作为输入,并且true如果数组中的所有元素都相同false则返回.
例如:
isUniform([1,2,1,1]); //应返回false isUniform([1,1,1,1]); //应该返回true
但是,if条件:
if (element !== myArray[0])
Run Code Online (Sandbox Code Playgroud)
在isUniform([1,2,1,1])的情况下似乎永远不会成立.
我错过了什么?
c++ ×6
base-class ×1
buffering ×1
casting ×1
constructor ×1
dictionary ×1
filesystems ×1
foreach ×1
gcc ×1
inode ×1
javascript ×1
linux ×1
scripting ×1
shell ×1
static-cast ×1
static-data ×1
stdout ×1
stl ×1
unbuffered ×1
unix ×1