标签: operator-keyword

如何在编程语言中消除对象/类之间的操作符定义?

我正在设计我自己的编程语言(如果您关注它在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++如何处理这样的歧义?

overloading operator-keyword

6
推荐指数
1
解决办法
231
查看次数

使用Android应用程序更改网络运营商

我正在尝试开发一个Android应用程序,它可以在地图上显示各种网络运营商的信号强度.问题是改变网络运营商的唯一方法是手工完成.

关于如何在不手动更改信息的情况下获取此信息的任何想法?我认为有内部/私人Android类可以做到这一点.

networking android operator-keyword

6
推荐指数
1
解决办法
3932
查看次数

在C#中扩展现有结构以添加运算符

我想扩展.NET的内置Color结构来添加像+或的新运算符-.
我将使用它们像:

Color c1 = Color.FromName("Red");
Color c2 = Color.FromName("Blue");
Color result = c2 - c1;
Run Code Online (Sandbox Code Playgroud)

可能吗?如果有,怎么样?

.net c# struct operator-keyword

6
推荐指数
2
解决办法
9459
查看次数

Scala:":="和":: ="运算符做什么?

我对scala很新.我浏览了这本书,并在代码中绊倒了这两个操作符.他们在做什么 ?

scala operator-keyword

6
推荐指数
1
解决办法
1313
查看次数

Powershell:使用转义参数调用运算符(&)( - %)不使用非静态参数

我的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工具,这就是我看到我遇到的麻烦.哦,我也需要我的例子中的所有空格(即需要在括号字符周围留出空格).

所以经过多次寻找答案后,我求助于你.提前致谢.

parameters powershell escaping call operator-keyword

6
推荐指数
1
解决办法
1万
查看次数

::运算符是否可以出现在与限定名称查找中的范围解析不同的上下文中?

已知范围解析运算符用于限定名称查找的目的.但是返回的价值是::多少?据我所知,它是postfix一元运算符.考虑以下:

namespace A
{
    //something
}

A:: //error: expected unqualified-id before ‘int’

int main(){ }
Run Code Online (Sandbox Code Playgroud)

你能解释一下这种行为吗?

c++ scope-resolution operator-keyword

6
推荐指数
1
解决办法
111
查看次数

`using`声明用于用户定义的文字运算符

是否可以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相同的方式用于函数命名空间中的任何其他函数或类型.

c++ namespaces using operator-keyword user-defined-literals

6
推荐指数
1
解决办法
626
查看次数

Angular 2:ngIf指令中比较运算符==和===之间的差异

我不明白为什么这两个运营商存在.在布尔比较的情况下,==和===似乎都有效,但是在枚举比较的情况下,只有'=='有效:

<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)

comparator operator-keyword angular

6
推荐指数
1
解决办法
3万
查看次数


乘法的顺序

C++在链式乘法中的作用是什么?

int a, b, c, d;
// set values
int m = a*b*c*d;
Run Code Online (Sandbox Code Playgroud)

c++ operator-precedence operator-keyword

5
推荐指数
1
解决办法
1315
查看次数