小编Per*_*hik的帖子

存在从'float'和'float'以及从'float'到'float'的隐式转换

可能是我在一段时间内得到的最好的错误信息,我很好奇出了什么问题.

原始代码

float currElbowAngle = LeftArm ? Elbow.transform.localRotation.eulerAngles.y 
                               : 360f - Elbow.transform.localRotation.eulerAngles.y
Run Code Online (Sandbox Code Playgroud)

我正在使用Unity3d和C#; LeftArm是一种bool类型,根据文档 Elbow.transform.localRotation.eulerAngles.y返回一个float值.

这段代码给了我错误:

存在从'float'和'float'以及从'float'到'float'的隐式转换

这解决了它:

float currElbowAngle = LeftArm ? (float) Elbow.transform.localRotation.eulerAngles.y 
                               : 360f - Elbow.transform.localRotation.eulerAngles.y
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:尝试沟通的错误是什么,实际出了什么问题?

更新1:弯头是一个GameObject,这个错误是在Visual Studio中

c# compiler-errors unity-game-engine

13
推荐指数
1
解决办法
398
查看次数

c#中神秘的"F冒号"

我正在使用ReSharper重构一些c#代码.我遇到的一件事是我不熟悉的ac #manrator.

在我的代码中,我有这个

Mathf.FloorToInt(NumRows/2)
Run Code Online (Sandbox Code Playgroud)

其中NumRows是一个整数.ReSharper建议我将其更改为

Mathf.FloorToInt(f: NumRows/2)
Run Code Online (Sandbox Code Playgroud)

我很确定这f:是一个标志,告诉它将NumRows转换为浮点数,但我找不到任何f:在线文档.任何人都可以详细说明究竟是f:做什么或将我链接到MSDN页面吗?

(虽然我很清楚f:做什么,但是很难在互联网上搜索冒号,我想在使用之前知道它做了什么)

更新1:无论我想做什么,我都对f-colon语法感兴趣

更新2:事实证明,实际上Visual Studio建议我可以添加参数名称'f'而不是ReSharper,但这不会改变正确的答案..

c# syntax

11
推荐指数
2
解决办法
706
查看次数

将数字列表传递给C++中的函数而不先构建数组?

我正在尝试构建一个以下列方式接受数组的函数:

int inCommon = findCommon({54,56,2,10}, 4);

int findCommon(int nums[], int len){
  for(int i=0; i<len; i++)  cout<<nums[i]<<endl;
  return 1;
} 
Run Code Online (Sandbox Code Playgroud)

注意,这实际上并不是我的函数所做的,但我会循环遍历数组.我只是想确定是否可以传递像{54,56,2,10}这样的数组,而不是必须创建一个数组并传递它?(像这样:

int theArray[]= {54,56,2,10};
int inCommon = findCommon(theArray,4);
Run Code Online (Sandbox Code Playgroud)

c++ arrays function

2
推荐指数
1
解决办法
2441
查看次数

返回字符串的C++函数不起作用,除非涉及到endl ......?

我在一个返回字符串的类中有一个函数.在这个函数中,我只能cout<<endl 在return语句之前添加函数时才能使它工作 .知道为什么会这样,或者我如何解决它?我在Mac上用Eclipse运行它

在"main.cpp"中:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include "Braid.h"
using namespace std;

static int size=3;

int main(){  
Braid * b1 = new Braid(size);
b1->setCanon();//creates canonical braid. 

cout<<"a ";
cout<<b1->getName()<<endl;
cout<<" b ";
}  
Run Code Online (Sandbox Code Playgroud)

在"Braid.h"中:

  public:  
        Braid(int);  
        void setCanon();  
        string getName(); 
    };  
Run Code Online (Sandbox Code Playgroud)

在"Braid.cpp"中:

string Braid::getName(){  
    string sName="";  

    /* body commented out
    for(int i=0; i<height; i++)
    {
        for(int j=2; j<(width-2); j++)
            {
                sName += boxes[i][j];
                sName += "|";
            }
        }

        */  
        //cout<<endl;
        return sName; …
Run Code Online (Sandbox Code Playgroud)

c++ string stl

0
推荐指数
1
解决办法
9228
查看次数

标签 统计

c# ×2

c++ ×2

arrays ×1

compiler-errors ×1

function ×1

stl ×1

string ×1

syntax ×1

unity-game-engine ×1