error CS0119: I declared the variable, but it is saying I need to declare it.
Hey all. Was wondering if someone could take a look at my code to tell me what I'm doing wrong. I can't figure it out and it should work, right?
I have polymorphic constructors for a class "ZoneRequirement". It would prefer to declare with integer array, but I can use an integer and it should make it an integer array first then run the first constructor. The code is below:
using UnityEngine;
using System.Collections;
public class ZoneRequirement : ICompare {
private _SingleRequirement requirement;
public ZoneRequirement(int[] req){
requirement = new _SingleRequirement (req);
}
public ZoneRequirement(int req){
int[] temp = new int[] {req};
ZoneRequirement (temp);
}
}
I am getting error, which would denote I am not declaring a variable for this line:
ZoneRequirement (temp);
error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
This should work? I am declaring a variable. It is declared it isn't a type! Right?? Does anyone see what I am doing incorrectly. An integer array isn't a type, right?
Thanks.
Answer by Ahndrakhul · Oct 31, 2016 at 05:18 AM
I think that you're getting that error because you're trying to call a constructor like you would a method. You would probably be better off if you just changed your second constructor to something like this:
public ZoneRequirement(int req)
{
requirement = new _SingleRequirement(new int[] { req });
}
Your answer
Follow this Question
Related Questions
Use a class like a function 1 Answer
Best way to learn how to utilize the Unity API? 2 Answers
please help i am geting error cs1061 1 Answer
Raycast shotgun help! 2 Answers