g ++로 컴파일 할 수있는 코드를 VS2015에서 컴파일하려고합니다. 나는 운이 좋지 않은 SO & Google을 둘러 보았지만 cmath는 MSDN에 문서화되어 있습니다. 정말 분명하거나 단순한 것을 놓치고 있다고 생각합니다.
cmath는 컴파일 중에 발생하는 대부분의 오류에 대한 많은 오류를 던지고 있으며 절반은 다음과 같은 형식입니다.
the global scope has no "<function>"
다른 것들은 형태에 있습니다
'<function>': redefinition; different exception specification
'<function>': identifier not found
'<function>': is not a member of "global namespace"
왜 이러한 오류가 발생하는지 이해하지 못하지만 math.h를 사용하면 대부분의 컴파일 오류가 사라집니다 (다른 표준 라이브러리의 일부 오류도 포함됨).
편집 : 요청 된대로 코드. sqrt 및 pow 함수를 사용하고 있습니다.
#include "vector.h"
#include <cmath>
using namespace vectormath;
vector::vector()
{
this->_x = 0;
this->_y = 0;
this->_z = 0;
this->_length = 0;
}
vector::vector(float x, float y, float z)
{
this->_x = x;
this->_y = y;
this->_z = z;
this->_length = sqrt(pow(_x, 2) + pow(_y, 2) + pow(_z, 2));
}
vector * vectormath::crossproduct(vector * a, vector * b)
{
vector * result = new vector();
result->_x = a->_y * b->_z - a->_z * b->_y;
result->_y = a->_z * b->_x - a->_x * b->_z;
result->_z = a->_x * b->_y - a->_y * b->_x;
return result;
}
point::point()
{
this->_x = 0.0;
this->_y = 0.0;
this->_z = 0.0;
}
point::point(float x, float y, float z)
{
this->_x = x;
this->_y = y;
this->_z = z;
}
float vectormath::dotproduct(vector a, vector b)
{
return a._x * b._x + a._y * b._y + a._z * b._z;
}
vector * vectormath::add(point * a, vector * b)
{
vector * c = new vector();
c->_x = a->_x + b->_x;
c->_y = a->_y + b->_y;
c->_z = a->_z + b->_z;
return c;
}
편집 : 및 vector.h
namespace vectormath
{
struct vector
{
float _x;
float _y;
float _z;
float _length;
vector();
vector(float x, float y, float z);
};
struct point
{
float _x;
float _y;
float _z;
point();
point(float x, float y, float z);
};
vector * crossproduct(vector*, vector*);
float dotproduct(vector a, vector b);
vector * add(point * a, vector * b);
}
차이점
#include <math.h>
과
#include <cmath>
같은 전자 풋 것들이다 sqrt
와 pow
글로벌 네임 스페이스에 (즉, 당신은 단지 말을 그들에게 참조 sqrt
또는 pow
)와 네임 스페이스로 후자의 풋 그들 std
(즉, 당신이 말하는 그들에게 참조 std::sqrt
또는 std::pow
).
std::
항상 접두사 를 붙이지 않으려면 전역 네임 스페이스에 개별 이름을 명시 적으로 넣을 수 있습니다.
using std::sqrt;
또는 (권장되지는 않지만) 다음 std
과 같이 전체를 가져올 수 있습니다 .
using namespace std;
그것의 문제는 많은 이름이 std
있고 당신은 아마 그들 모두를 정말로 원하지 않을 것입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다