【C++】全局作用域限定符::

c++自定义的Vector3在命名空间threeD中,但Raylib的struct Vector3没有用命名空间限定。我该怎么在threeD::Vector3的LocalVec3ToRayVec()中返回Raylib的struct Vector3

namespace threeD
{
	class Vector3
	{
	public:
		Vector3(){}
		Vector3(float x, float y, float z):x(x),y(y),z(z){}
		Vector3(const Vector3& another)noexcept:x(another.x),y(another.y),z(another.z)
		{}
		Vector3& operator=(const Vector3& another)noexcept
		{
			if (this == &another)
				return *this;
			x = another.x;
			y = another.y;
			z = another.z;
			return *this;
		}
		//转成Raylib的Vector3
		static struct Vector3 LocalVec3ToRayVec(const threeD::Vector3& vec)
		{
			Vector3 vec3{vec.x,vec.y,vec.z};
			return vec3;
		}
namespace threeD
{
    class Vector3
    {
    public:
        // ... 其他代码 ...
        
        // 转成Raylib的Vector3
        static ::Vector3 LocalVec3ToRayVec(const threeD::Vector3& vec)
        {
            ::Vector3 raylibVec{vec.x, vec.y, vec.z};  // 使用全局作用域限定符::
            return raylibVec;
        }
    };
}
posted @ 2026-03-20 01:22  仰望星河Leon  阅读(3)  评论(0)    收藏  举报