我在perl和php中都看过这个(例如:$ variable - > define something),但之前我从未真正使用它.这个运算符的目的是什么 - >它是分配值还是传递参数?
谢谢
我正在开发一个具有名为Vector2的对象的项目
public static class Vector2 {
public Vector2 (float x, float y) {
this.x = x;
this.y = y;
}
public float x;
public float y;
public static Vector2 ZERO = new Vector2 (0, 0);
public static Vector2 FORWARD = new Vector2 (0, 1);
public static Vector2 LEFT = new Vector2 (1, 0);
public static float Distance (Vector2 a, Vector2 b) {
return (float) Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}
}
Run Code Online (Sandbox Code Playgroud)
并希望做到以下几点:
Vector2 a = new …Run Code Online (Sandbox Code Playgroud) 以下关键字的目的是什么?
and bitand compl not_eq or_eq xor_eq
and_eq bitor not or xor
Run Code Online (Sandbox Code Playgroud)
如果他们只是直接相当于:
&& & ~ != |= ^=
&= | ! || ^
Run Code Online (Sandbox Code Playgroud) 我只是尝试创建一个简单的类,让我弄清楚文件的长度:
public class Size {
long s = 0;
int a;
public static void main(String[]args){
new Size();
}
Size(){
try{
FileInputStream str = new FileInputStream("E:/Eclipse/Resources/smile.jpg");
while(a != null){
s++;
}
}catch (IOException e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到了一个问题
while(a != null)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
对于参数类型int,null,运算符!=未定义
任何想法为什么阻止这种情况?
在C#我可以表达这个:
var xe = XElement.Parse("<foo></foo>");
var maybe = (bool?)xe.Element("bar");
Run Code Online (Sandbox Code Playgroud)
如何在F#中表达?
编辑:我确实找到了这个辅助函数
let inline conv (x : ^a) : ^b = ((^a or ^b) : (static member op_Explicit : ^a -> ^b) (x))
Run Code Online (Sandbox Code Playgroud) xelement f# linq-to-xml operator-keyword explicit-conversion
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
print_r(array_filter($array1, "odd"));
function odd($var)
{
// returns whether the input integer is odd//
return($var & 1);
}
Run Code Online (Sandbox Code Playgroud)
在返回值中有什么操作&符?它如何返回奇数
我正在尝试创建自己的翻译器.这是大学的工作.我的班级译者需要一个迭代器.
class Translator
{
private:
map <string,Word> translator;
public:
class iterator
{
friend class Translator;
private:
map<string,Word>::iterator itm;
public:
iterator operator++();
pair <string,Word> &operator*();
bool operator==(const iterator &it)const;
};
};
Run Code Online (Sandbox Code Playgroud)
我想超载operator*();
这是代码.
pair <string, Word>& Translator::iterator::operator*()
{
return (*itm);
}
Run Code Online (Sandbox Code Playgroud)
错误:
invalid initialization of reference of type ‘std::pair<std::basic_string<char>, Word>&’ from expression of type ‘std::pair<const std::basic_string<char>, Word>
C++在链式乘法中的作用是什么?
int a, b, c, d;
// set values
int m = a*b*c*d;
Run Code Online (Sandbox Code Playgroud) 我正在发现C++,我想使用模板创建一个迷你数学Matrix librairy.
在这里,我想重载运算符*.
如果我描述了这样的矩阵:M(y, x)以M矩阵的名称,y以及x高度和宽度,矩阵乘法看起来应该:
M(a, b) * N(b, c) = R(a, c)
Run Code Online (Sandbox Code Playgroud)
目前我有这个代码:
template<unsigned int y, unsigned int x>
class Matrix
{
public:
Matrix() { }
~Matrix() { }
Matrix<y, x2>& operator*(const Matrix<y2, x2>& right)
{
// code...
}
private:
std::array<std::array<double, x>, y> m_values;
};
Run Code Online (Sandbox Code Playgroud)
所以我希望能够将两个不同的矩阵相乘:
Matrix<3, 4> m;
Matrix<4, 2> n;
// fill the matrix with values
Matrix<3, 2> o = m * n;
Run Code Online (Sandbox Code Playgroud)
我搜索了但是我没有找到这个问题的答案(也许是因为我真的不知道我必须要搜索的内容).
谢谢你的帮助 :)
我正在寻找找到的Octave函数的代码,并且发现了冒号运算符的怪异用法。我找不到文档或MathWorks官方博客(例如Colon Operator)中解释的这种行为。
假设我们有两个向量:
>> a=[1,2,3]
a =
1 2 3
>> b=[7,8,9]
b =
7 8 9
Run Code Online (Sandbox Code Playgroud)
现在,如果使用冒号运算符,您将:
>> a:b
ans =
1 2 3 4 5 6 7
Run Code Online (Sandbox Code Playgroud)
经过几次尝试,我了解到上述用法等同于:
>> a(1):b(1)
ans =
1 2 3 4 5 6 7
Run Code Online (Sandbox Code Playgroud)
我的假设正确吗?
某处有一些文档吗?