首先,我需要知道,如果我想做的事情是可能的.如果有可能,我需要知道如何.
它更容易证明问题而不是解释它,所以这里:
我有一个"增强记录"(目的 - 虽然对这个问题不重要 - 是产生一个"智能字符串"类型,以取代普通的字符串类型):
TLKString = record
Value: String;
// Some methods here to operate on and build String values
// Allows me to assign String values directly to "instances"
// of this record type! I have others (hence "overload") to
// handle other data types (such as Integer etc.)
class operator Implicit(const AValue: String): TLKString; overload;
end;
Run Code Online (Sandbox Code Playgroud)
我现在可以使用这个TLKString类型,如下所示:
var
LSmartString: TLKString;
begin
LSmartString := 'Hello World'; // The "Implicit" operator then
// assigns this to LSmartString.Value …Run Code Online (Sandbox Code Playgroud) 我正在训练我的C++,我正在尝试编写一个能够使用链表来表示以下数字的库:
999999999*([i = 0]Σ[999999999] 1000000000 ^ i)
例如,如果我的号码是711381450277869054011,它将表示如下:
711*1000000000 ^ 2 + 381450277*1000000000 ^ 1 + 869054011*1000000000 ^ 0
所以,这是我的LL的结构及其功能:
typedef struct node* ll;
struct node
{
unsigned int data;
ll next;
};
bool insert(ll&, unsigned int);
// ...
void copy(ll&, ll);
void destroy(ll&);
Run Code Online (Sandbox Code Playgroud)
这是我的无符号非常长的整数类:
class uli
{
public:
uli();
~uli();
// <<, >>, =, operators...
uli& operator +=(const uli&);
uli& operator +=(char*);
const uli operator +(const uli&);
private:
ll head;
};
uli::uli()
{
head …Run Code Online (Sandbox Code Playgroud) 我有一个类,我想在c#中重载==运算符.我已经有一个正常的.Equals覆盖.当我尝试使用我的==运算符时,它在我的对象(Person)上给了我一个空引用异常.如果我尝试检查它是否为null,它将依次调用相同的运算符来检查它是否为null并创建一个无限循环.这似乎是一个巨大的缺陷,我无法找到正确的方法来做到这一点.
public static bool operator ==(Person person, object obj)
{
return person == null ? person.Equals(obj) : false;
}
public static bool operator !=(Person person, object obj)
{
return !(person == obj);
}
Run Code Online (Sandbox Code Playgroud) 我要检查if的/经营者有没有剩余或不:
int x = 0;
if (x = 16 / 4), if there is no remainder:
then x = x - 1;
if (x = 16 / 5), if remainder is not zero:
then x = x + 1;
Run Code Online (Sandbox Code Playgroud)
如何检查是否有剩余C?以及
如何实施它?
为什么下面的代码真正起作用?
码
var firstDate = new Date();
// some time passing here
var secondDate = new Date();
// Difference seems to contain difference in miliseconds.
var difference = secondDate - firstDate;
Run Code Online (Sandbox Code Playgroud)
我相信,我得到的等同于secondDate.getTime() - firstDate.getTime()。唯一的问题是,在后台如何转换为毫秒数?这是某种运算符重载吗?
int m = 5, d = 12, y = 1975, val;
// May 12, 1975
Run Code Online (Sandbox Code Playgroud)
有人可以在下面的代码行中解释逗号运算符的功能/目的:
val = (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7;
Run Code Online (Sandbox Code Playgroud)
在上述行写由麦克·基思来计算给定日期(d =天,M =月,Y =年)一周中的一天.其中星期日= 0,星期一= 1,星期二= 2,星期三= 3,星期四= 4,星期五= 5,星期六= 6.我知道如果d + = m <3,则y--执行,否则y -2执行.我不明白的是y-2之后逗号的目的.
我在R中遇到以下情况:
x=x+y%o%c(1.5,1.5)
Run Code Online (Sandbox Code Playgroud)
我想知道%o%这里的含义是什么.我尝试谷歌搜索,但没有太多运气
我正在从Zed Shaw的学习Python中学习Python的基础知识.我目前正在第36章(符号审查),并遇到了'as'运算符.我需要在Python中搜索它的用途.我知道这个问题很广泛,但我没有在python.docs或SO上找到任何东西.这个运营商做什么?
我想写一个String类.并希望使用下标来访问我的String中的元素.所以,我编写了两个成员函数,一个用于获取String中的元素,另一个用于在String中设置元素.请看下面的代码;
#include <iostream>
#include <algorithm>
using namespace std;
class String {
public:
String();
String(const char *s);
char &operator[] (int index);
char operator[] (int index) const;
private:
char *arr;
int len;
};
String::String() {
arr = new char[1];
arr[0] = '\0';
len = 0;
}
String::String(const char *s) {
len = strlen(s);
arr = new char[len + 1];
std::copy(s, s + len + 1, arr);
}
//mutator operator[] ---> used to change data …Run Code Online (Sandbox Code Playgroud) 假设我有一个名为Component的简单c ++组件,如下所示:
class Component {
public:
explicit Component(int i)
: _integer(i) {
}
~Component() {
}
private:
int _integer;
Component(const Component&);
Component& operator=(const Component&);
};
Run Code Online (Sandbox Code Playgroud)
我通常在代码中发现我读了最后两条指令,但我真的不明白.是否必须正确使用该组件?
operator-keyword ×10
c++ ×3
overloading ×3
c ×2
c# ×1
comma ×1
date ×1
delphi ×1
delphi-xe2 ×1
javascript ×1
linked-list ×1
methods ×1
python ×1
r ×1
record ×1
recursion ×1