当函数退出时,bash中是否有可能调用某些命令.我的意思是:
function foo
{
# something like this maybe?
trap "echo \"exit function foo\"" EXIT
# do something
}
foo
Run Code Online (Sandbox Code Playgroud)
我希望打印退出函数foo.
我有以下c ++代码。我可以在Linux机器上使用g ++ 4.9.2进行编译。然后,当我运行它时,它会显示10。似乎在默认构造函数中创建了一个新对象并将其分配给使用const_cast创建的指针。没有内存泄漏(我使用valgrind检查了)。这是某种未定义的行为还是合法的?
#include <iostream>
using namespace std;
class A
{
public:
A() : x(0)
{
A *tmp = const_cast<A*>(this);
*tmp = A(10);
}
A(int x)
{
this->x = x;
}
int getX() const
{
return x;
}
private:
int x;
};
int main()
{
A a;
cout << a.getX() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在maven下载依赖的过程中,其中一个由于网络问题而失败:
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-failsafe-plugin/2.16/maven-failsafe-plugin-2.16.pom
Plugin org.apache.maven.plugins:maven-failsafe-plugin:2.16 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-failsafe-plugin:jar:2.16
Run Code Online (Sandbox Code Playgroud)
我想n在n可配置的时候重试它。我怎样才能做到这一点?