Jump to content

Namespace function overloading


photo

Recommended Posts

Is it can be done?

I do next:

namespace Math
{
	int round(float value)
	{
		int result;

		if (value < 0)
		{
			result = ceil(value - 0.5);
		}
		else
		{
			result = floor(value + 0.5);
		}

		return int(result);
	}

	vec3 round(vec3 value)
	{
		vec3 result = value;

		result.x = round(result.x);
		result.y = round(result.y);
		result.z = round(result.z);

		return result;
	}
};

And have next error:

13:49:22 vec3 round(vec3 value)
13:49:22 source/scripts/Math.h:196: Interpreter::parse_function_prototype(): different argument prototype "value" in "round" function

Link to comment

This is an another Unigine Script pattern:

 

namespace Math
{
	int round(float value) {
                       if(is_float(value)) {
				if(value < 0) return int(ceil(value - 0.5f)));
			return int(floor(value + 0.5f));
		}
		if(is_vec3(value)) {
				value.x = round(value.x);
			value.y = round(value.y);
			value.z = round(value.z);
			return value;
		}			
	}
}

Link to comment
×
×
  • Create New...