동적 메모리 할당을 사용하여 새 개체를 만들고 컴파일하려고하면 다음 오류가 계속 표시됩니다. 나는이 오류가 왜 나타나는지 잘 모르겠다.오류 : 배열의 크기가 정수형이어야합니다. [-fpermissive]
// target constructor for delegating constructor
template <typename NUM1, typename NUM2> // any numeric types of user input for dimensions and magnitude will be static_cast to unsigned int and double respectively
EuclideanVector(const NUM1 dimensions, const NUM2 magnitude){
// static cast to unsigned int for temp and assign dimensions_ to that
unsigned int temp = static_cast<unsigned int>(dimensions);
dimensions_ = new unsigned int (temp);
// assign pointer "magnitude_" to dynamically-allocated memory of new unnamed array<double> object of size "dimensions_"
magnitude_ = new double [dimensions_];
// fill the array<double> object "magnitude_" a number of "dimensions_" times, with the <double> value of "magnitude_" for each dimension
std::fill_n(magnitude_, dimensions_, static_cast<double>(magnitude));
updateNormal();
}
어떻게이 템플릿을 호출합니까? – JVApen
위임자 생성자를 사용합니다. 템플릿 EuclideanVector (const NUM dimensions = 1) : EuclideanVector (dimensions, 0.0) {}; –
iteong
컴파일하는 동안 경고도 있지만 중요한 것은 아니지만 경고를 해결하는 방법을 알려 주시면 큰 도움이 될 것입니다. EuclideanVector.h : 'evec :: EuclideanVector :: 유클리드 벡터 (NUM1, NUM2) [NUM1 = int; NUM2 = double] ': EuclideanVector.h : 46 : 50 :'NUM = int와 함께 'evec :: EuclideanVector :: EuclideanVector'에서 필요 ' EuclideanVectorTester.cpp : 9 : 30 : 여기에서 필요 – iteong