我正在设计我自己的编程语言(如果您关注它在www.btetrud.com上称为Lima),我正试图围绕如何实现运算符重载.我决定在特定对象上绑定运算符(它是基于原型的语言).(它也是一种动态语言,其中'var'就像javascript中的'var' - 一个可以包含任何类型值的变量).
例如,这将是一个带有重新定义的+运算符的对象:
x =
{ int member
operator +
self int[b]:
ret b+self
int[a] self:
ret member+a
}
Run Code Online (Sandbox Code Playgroud)
我希望它的作用相当明显.当x是右操作数和左操作数时定义运算符(self用于表示).
当你有两个以开放式方式定义运算符的对象时,问题是该怎么做.例如,您在这种情况下做了什么:
A =
{ int x
operator +
self var[b]:
ret x+b
}
B =
{ int x
operator +
var[a] self:
ret x+a
}
a+b ;; is a's or b's + operator used?
Run Code Online (Sandbox Code Playgroud)
因此,对这个问题的一个简单回答是"好吧,不要做出含糊不清的定义",但它并不那么简单.如果包含具有A类型对象的模块,然后定义B类型的对象,该怎么办?
你如何创建一种语言来防止其他对象劫持你想要对你的运营商做什么?
C++将运算符重载定义为类的"成员".C++如何处理这样的歧义?
我正在尝试开发一个Android应用程序,它可以在地图上显示各种网络运营商的信号强度.问题是改变网络运营商的唯一方法是手工完成.
关于如何在不手动更改信息的情况下获取此信息的任何想法?我认为有内部/私人Android类可以做到这一点.
我想扩展.NET的内置Color结构来添加像+或的新运算符-.
我将使用它们像:
Color c1 = Color.FromName("Red");
Color c2 = Color.FromName("Blue");
Color result = c2 - c1;
Run Code Online (Sandbox Code Playgroud)
可能吗?如果有,怎么样?
我对scala很新.我浏览了这本书,并在代码中绊倒了这两个操作符.他们在做什么 ?
我的Powershell脚本需要使用一组非常复杂的参数调用EXE.我正在使用Powershell 3.0,并且必须坚持使用该版本.唉,即使是"魔术"逃脱的操作员(--%)也没有帮助我.例如,使用Call运算符,请考虑以下因素:
& other.exe --% action /mode fast /path:"location with spaces" /fancyparam { /dothis /dothat:"arg with spaces" } /verbose
Run Code Online (Sandbox Code Playgroud)
现在,如果它很简单,我的脚本可以很容易地正常工作.但事情并非那么简单."other.exe"的参数可能不同,具体取决于我脚本中较早的用户选择.所以相反,我需要提前建立这些参数,也许是这样的:
$commandArgs = 'action /mode ' + $userMode + ' /path:"location with spaces" /fancyparam { /dothis /dothat:"' + $userArgs + " } /verbose'
Run Code Online (Sandbox Code Playgroud)
因此我会这样调用:
& other.exe --% $commandArgs
Run Code Online (Sandbox Code Playgroud)
...好吧,期望这--%意味着它只是传递一个原始字符串$commandArgs.但是如果没有--%,powershell会自动引用$ commandArgs的内容,这些内容实际上会混淆内部引用(更不用说打破其他程序首先需要的'action'参数).换句话说,我已经尝试嵌入--%我的$ commandArgs字符串内部,但损坏已经在它被解析的时候完成了(我不认为它甚至可以这样工作).
请注意,这个例子只是我需要执行的实际命令的1/4 - 其中包括更多用户参数,引号和其他有趣的字符,这些字符会让我匆忙逃离地狱!我也一直在使用echoargs.exe工具,这就是我看到我遇到的麻烦.哦,我也需要我的例子中的所有空格(即需要在括号字符周围留出空格).
所以经过多次寻找答案后,我求助于你.提前致谢.
已知范围解析运算符用于限定名称查找的目的.但是返回的价值是::多少?据我所知,它是postfix一元运算符.考虑以下:
namespace A
{
//something
}
A:: //error: expected unqualified-id before ‘int’
int main(){ }
Run Code Online (Sandbox Code Playgroud)
你能解释一下这种行为吗?
是否可以using为文字运算符声明operator ""?
例如,
#include <chrono>
namespace MyNamespace
{
constexpr std::chrono::hours operator "" _hr(unsigned long long n){
return std::chrono::hours{n};
}
// ... other stuff in the namespace ...
}
using MyNamespace::operator""; // DOES NOT COMPILE!
int main()
{
auto foo = 37_hr;
}
Run Code Online (Sandbox Code Playgroud)
我的解决方法是将这些运算符放在它们自己的嵌套命名空间中literals,这允许using namespace MyNamespace::literals;,但这似乎有点不优雅,我不明白为什么using指令不能以operator相同的方式用于函数命名空间中的任何其他函数或类型.
我不明白为什么这两个运营商存在.在布尔比较的情况下,==和===似乎都有效,但是在枚举比较的情况下,只有'=='有效:
<div class="interventionGroup">
<div class="interventionGroupHeader transition_1s" (click)="onClickHeader()">
{{GroupName}}
<div *ngIf="expanded == true" class="expand-icon"><i class="material-icons">expand_less</i></div> <!-- WORKS -->
<div *ngIf="expanded === false" class="expand-icon"><i class="material-icons expand-icon">expand_more</i></div> <!-- WORKS -->
</div>
<button *ngIf="GroupType == GroupTypeEnum.mesInterventions">dfdsfsd</button> <!-- WORKS -->
<div style="list-style-type:none" *ngIf="expanded === true">
<div *ngFor="let intervention of interventions"
(click)="onClick(intervention)">
<intervention-button [intervention]="intervention"></intervention-button>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 可能重复:
等式(== double equals)和identity(=== triple equals)比较运算符有何不同?
参考 - 这个符号在PHP中意味着什么?
php不等于!=和!==
这段代码片段中有哪些!==和===运算符?
if ( $a !== null ) // do something
if ( $b === $a ) // do something
Run Code Online (Sandbox Code Playgroud) C++在链式乘法中的作用是什么?
int a, b, c, d;
// set values
int m = a*b*c*d;
Run Code Online (Sandbox Code Playgroud) operator-keyword ×10
c++ ×3
.net ×1
android ×1
angular ×1
c# ×1
call ×1
comparator ×1
escaping ×1
namespaces ×1
networking ×1
overloading ×1
parameters ×1
php ×1
powershell ×1
scala ×1
struct ×1
syntax ×1
using ×1