小编use*_*535的帖子

使用powershell将空参数传递给可执行文件

传递给命令时,Powershell似乎丢弃空字符串参数.我有这个代码

PS D:\> $b.name = "foo bar"
PS D:\> ./echoargs $b.name
Arg 0 is D:\echoargs.exe
Arg 1 is foo bar
PS D:\> $b.name = ""
PS D:\> ./echoargs $b.name
Arg 0 is D:\echoargs.exe
Run Code Online (Sandbox Code Playgroud)

您可以假设$ b有一个'name'成员.即使值为空字符串,我如何将其作为参数传递给exe.我尝试过使用call运算符但没有成功.

powershell command-line

10
推荐指数
2
解决办法
9613
查看次数

重新解释从指针向量转换为const指针向量安全吗?

这种转换类型是否安全?

vector<int*> a;
const vector<const int*>& b = reinterpret_cast<const vector<const int*>&>(a);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,静态转换显然不起作用,因为模板参数正在改变.但是通过这个重新解释演员,我只是将constness添加到基本相同的类型.那么这对所有实际目的来说都是安全的吗?

c++ const vector reinterpret-cast

9
推荐指数
1
解决办法
895
查看次数

运算符在模板类外部重载,具有隐式转换

我有一个像这样定义的模板类

template<class T> class Wrap
{
    /* ... */
public:
    Wrap(const T&);
    /* other implicit conversions */

    /* ... */
};
Run Code Online (Sandbox Code Playgroud)

我想在类之外为这个类定义所有比较运算符

template<typename T> bool operator == (const Wrap<T>&, const Wrap<T>&)
{
    // Do comparison here
}
Run Code Online (Sandbox Code Playgroud)

但是,此声明不支持隐式转换const T&或任何其他类型const Wrap<T>&.

所以我的问题是当其中一个操作数是类型Wrap<T>而另一个不是类型时,我如何使它支持隐式转换.我不想为每个可能的排列编写每个运算符的多个声明.

c++ operator-overloading

7
推荐指数
1
解决办法
656
查看次数