[問題] include標頭檔後的編譯錯誤
開發平台(Platform):
Visual C++ 2010 EXPRESS
問題(Question):
我的問題類似此網頁:http://tinyurl.com/4behyr2
(google搜尋"關於error C4430: missing type specifier的問題"可以找到此頁面)
詳情請見程式碼.請把以下程式組合成一個project.
錯誤結果(Wrong Output):
主要的錯誤訊息為:
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2143: syntax error : missing ',' before '&'
補充說明(Supplement):
我的問題起源於我需要在 EulerAngle.h 與 EulerAngle.cpp 中用到其他的 class.
當我把EulerAngle.h內的
#include "RotationMatrix.h"拿掉,
並將 void fromRotationMatrix(const RotationMatrix &m) 那行註解,
也把 EulerAngle.cpp 從project中移除後,我的程式才能順利編譯.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.11.75
→
03/17 16:18, , 1F
03/17 16:18, 1F
→
03/17 16:19, , 2F
03/17 16:19, 2F
→
03/17 16:19, , 3F
03/17 16:19, 3F
→
03/17 16:20, , 4F
03/17 16:20, 4F
→
03/17 16:20, , 5F
03/17 16:20, 5F
→
03/17 16:20, , 6F
03/17 16:20, 6F
→
03/17 16:20, , 7F
03/17 16:20, 7F
http://paste.plurk.com/show/399996/
http://paste.plurk.com/show/399997/
http://paste.plurk.com/show/399998/
http://paste.plurk.com/show/399999/
檔案補齊了!!!
※ 編輯: luckychild 來自: 140.120.11.75 (03/17 16:22)
→
03/17 16:28, , 8F
03/17 16:28, 8F
#ifndef EULERANGLE_H
#define EULERANGLE_H
#include <cmath>
#include "FundMath.h"
#include "RotationMatrix.h"
class EulerAngle
{
public:
// Store the three angles in RADIANS
double phi, theta, psi;
// Default constructor
EulerAngle()
{
phi = 0.0; theta = 0.0; psi = 0.0;
}
// Construct from three values in RADIANS.
EulerAngle(double PHI, double THETA, double PSI): phi(PHI), theta(THETA),
psi(PSI) {}
// Set to identity triple (all zeros)
//void identity() { phi = theta = psi = 0.0; }
// Determine "canonical" Euler angle triple
//void canonize();
// Convert a rotation matrix to Euler Angle form.
void fromRotationMatrix(const RotationMatrix &m);
};
#endif // #ifndef EULERANGLE_H
------------------------------------------------------------------------------
#include "EulerAngle.h"
void EulerAngle::fromRotationMatrix(const RotationMatrix &m)
{
// Extract cos(theta) from m33.
double cos_theta = m.m33;
// Check for Gimbel lock
if(cos_theta >= 0.99999)
{
phi = 0.0;
theta = 0.0;
psi = atan2(m.m12,m.m22);
}
else if(cos_theta <= -0.99999)
{
phi = 0.0;
theta = PI;
psi = atan2(m.m12,m.m22);
}
else
{
phi = atan2(-m.m31,m.m32);
if(sin(phi)*sin(theta) * m.m31 < 0.0)
phi = atan2(m.m31,m.m32);
theta = acos(m.m33);
psi = atan2(m.m13,m.m23);
}
}
------------------------------------------------------------------------------
#ifndef ROTATIONMATRIX_H
#define ROTATIONMATRIX_H
#include <iostream>
#include "FundMath.h"
#include "Vector3.h"
#include "EulerAngle.h"
#include "Quaternion.h"
//////////////////////////////////////////////////////////////////////////////
// class RotationMatrix
//
// Implement a simple 3x3 matrix that is used for ROTATION ONLY.
// The matrix is assumed to be orthogonal.
// The direction of transformation is specified at the time of transformation.
//////////////////////////////////////////////////////////////////////////////
class RotationMatrix
{
public:
double m11, m12, m13;
double m21, m22, m23;
double m31, m32, m33;
// Set to identity
void identity();
// Setup the matrix with a specified orientation
void setup(const EulerAngle &orientation);
// Setup the matrix from a quaternion, assuming the
// quaternion performs the rotation in the
// specified direction of transformation
void FromInertialtoObjectQuaternion (const Quaternion &q);
//void fromObjectToInertialQuaternion(const Quaternion &q);
// Perform rotations
Vector3 InertialtoObject (const Vector3 &v) const;
//Vector3 objectToInertial(const Vector3 &v) const;
};
#endif // #ifndef ROTATIONMATRIX_H
------------------------------------------------------------------------------
#include "RotationMatrix.h"
void RotationMatrix::identity()
{
m11 = 1.0; m12 = 0.0; m13 = 0.0;
m21 = 0.0; m22 = 1.0; m23 = 0.0;
m31 = 0.0; m32 = 0.0; m33 = 1.0;
}
void RotationMatrix::setup(const EulerAngle &orientation)
{
// Fetch sine and cosine of angles
double sphi, cphi, sth, cth, spsi, cpsi;
SinCos (&sphi, &cphi, orientation.phi);
SinCos (&sth, &cth, orientation.theta);
SinCos (&spsi, &cpsi, orientation.psi);
// Fill in the matrix elements
// cf. Marion p442
m11 = cpsi * cphi - cth * sphi * spsi;
m21 = -spsi * cphi - cth * sphi * cpsi;
m31 = sth * sphi;
m12 = cpsi * sphi + cth * cphi * spsi;
m22 = -spsi * sphi + cth * cphi * cpsi;
m32 = -sth * cphi;
m13 = spsi * sth;
m23 = cpsi * sth;
m33 = cth;
}
void RotationMatrix::FromInertialtoObjectQuaternion(const Quaternion &q)
{
//q.Normalize();
double q1q1 = q.q1 * q.q1;
double q2q2 = q.q2 * q.q2;
double q3q3 = q.q3 * q.q3;
double q4q4 = q.q4 * q.q4;
double q1q2 = q.q1 * q.q2;
double q1q3 = q.q1 * q.q3;
double q1q4 = q.q1 * q.q4;
double q2q3 = q.q2 * q.q3;
double q2q4 = q.q2 * q.q4;
double q3q4 = q.q3 * q.q4;
m11 = 1.0 - 2.0 * (q2q2 + q3q3);
m12 = 2.0 * (q1q2 + q3q4);
m13 = 2.0 * (q1q3 - q2q4);
double NormX = sqrt(m11*m11 + m12*m12 + m13*m13);
m11 = (m11/NormX);
m12 = (m12/NormX);
m13 = (m13/NormX);
m21 = 2.0 * (q1q2 - q3q4);
m22 = 1.0 - 2.0 * (q1q1 + q3q3);
m23 = 2.0 * (q2q3 + q1q4);
double NormY = sqrt(m21*m21 + m22*m22 + m23*m23);
m21 = (m21/NormY);
m22 = (m22/NormY);
m23 = (m23/NormY);
m31 = 2.0 * (q1q3 + q2q4);
m32 = 2.0 * (q2q3 - q1q4);
m33 = 1.0 - 2.0 * (q1q1 + q2q2);
double NormZ = sqrt(m31*m31 + m32*m32 + m33*m33);
m31 = (m31/NormZ);
m32 = (m32/NormZ);
m33 = (m33/NormZ);
//cout << "matrix= " << endl;
//cout << m11 << ", " << m12 << ", " << m13 << endl;
//cout << m21 << ", " << m22 << ", " << m23 << endl;
//cout << m31 << ", " << m32 << ", " << m33 << endl;
}
Vector3 RotationMatrix::InertialtoObject(const Vector3 &v) const
{
// 1.Rotate the object rather than the coordinate system!
// 2.This is positive rotation.
// 3.IMPORTANT! Both are positive rotation so both are not equivalent.
// | m11 m12 m13 |
// [ix iy iz]| m21 m22 m23 | = [ox oy oz]
// | m31 m32 m33 |
Vector3 u( v.x*m11 + v.y*m21 + v.z*m31,
v.x*m12 + v.y*m22 + v.z*m32,
v.x*m13 + v.y*m23 + v.z*m33 );
// 1.Rotate the coordinate system.
// 2.This is positive rotation.
// | m11 m12 m13 | |ix|
// | m21 m22 m23 | |iy| = [ox oy oz]
// | m31 m32 m33 | |iz|
//Vector3 u( v.x*m11 + v.y*m12 + v.z*m13,
// v.x*m21 + v.y*m22 + v.z*m23,
// v.x*m31 + v.y*m32 + v.z*m33);
return u;
}
------------------------------------------------------------------------------
#ifndef QUATERNION_H
#define QUATERNION_H
#include <iostream>
#include <cmath>
#include <vector>
#include "EulerAngle.h"
//using namespace std;
using std::cout;
using std::endl;
using std::vector;
class Quaternion
{
public:
double q1, q2, q3, q4;
double q1_current, q2_current, q3_current, q4_current;
double qv1, qv2, qv3, qv4;
double qv1_current, qv2_current, qv3_current, qv4_current;
double qv1_temp1, qv2_temp1, qv3_temp1, qv4_temp1;
double qv1_temp2, qv2_temp2, qv3_temp2, qv4_temp2;
double qv1_temp3, qv2_temp3, qv3_temp3, qv4_temp3;
double qa1, qa2, qa3, qa4;
double qa1_temp1, qa2_temp1, qa3_temp1, qa4_temp1;
double qa1_temp2, qa2_temp2, qa3_temp2, qa4_temp2;
double qa1_temp3, qa2_temp3, qa3_temp3, qa4_temp3;
Quaternion(){}
Quaternion(EulerAngle &angle)
{
SetInitialValue(angle);
qv1 = 0; qv2 = 0; qv3 = 0; qv4 = 0;
qa1 = 0; qa2 = 0; qa3 = 0; qa4 = 0;
q1_current = 0.0; q2_current = 0.0; q3_current = 0.0; q4_current = 0.0;
qv1_current = 0.0; qv2_current = 0.0; qv3_current = 0.0; qv4_current = 0.0;
qa1_temp1 = 0.0; qa2_temp1 = 0.0; qa3_temp1 = 0.0; qa4_temp1 = 0.0;
qa1_temp2 = 0.0; qa2_temp2 = 0.0; qa3_temp2 = 0.0; qa4_temp2 = 0.0;
qa1_temp3 = 0.0; qa2_temp3 = 0.0; qa3_temp3 = 0.0; qa4_temp3 = 0.0;
}
void SetInitialValue(EulerAngle &angle);
void Normalize();
Quaternion operator *(const Quaternion &a) const;
Quaternion &operator *=(const Quaternion &a);
friend Quaternion Conjugate(const Quaternion &q);
friend Quaternion Difference(Quaternion temp, Quaternion qua);
friend void W_Matrix(vector<vector<double> > &w, Quaternion qua);
friend void W_Transverse(vector<vector<double> > &wt,
Quaternion qua);
};
# endif
------------------------------------------------------------------------------
#include "Quaternion.h"
void Quaternion::SetInitialValue(EulerAngle &angle)
{
double HalfTheta = 0.5 * angle.theta;
double HalfPhiMPsi = 0.5 * (angle.phi - angle.psi);
double HalfPhiPPsi = 0.5 * (angle.phi + angle.psi);
q1 = sin(HalfTheta) * cos(HalfPhiMPsi);
q2 = sin(HalfTheta) * sin(HalfPhiMPsi);
q3 = cos(HalfTheta) * sin(HalfPhiPPsi);
q4 = cos(HalfTheta) * cos(HalfPhiPPsi);
Normalize();
qv1=0.0; qv2=0.0; qv3=0.0; qv4=0.0;
qa1=0.0; qa2=0.0; qa3=0.0; qa4=0.0;
q1_current = 0.0; q2_current = 0.0; q3_current = 0.0; q4_current = 0.0;
qv1_current = 0.0; qv2_current = 0.0; qv3_current = 0.0; qv4_current = 0.0;
qa1_temp1 = 0.0; qa2_temp1 = 0.0; qa3_temp1 = 0.0; qa4_temp1 = 0.0;
qa1_temp2 = 0.0; qa2_temp2 = 0.0; qa3_temp2 = 0.0; qa4_temp2 = 0.0;
qa1_temp3 = 0.0; qa2_temp3 = 0.0; qa3_temp3 = 0.0; qa4_temp3 = 0.0;
qv1_temp1 = 0.0;
qv2_temp1 = 0.0;
qv3_temp1 = 0.0;
qv4_temp1 = 0.0;
qv1_temp2 = 0.0;
qv2_temp2 = 0.0;
qv3_temp2 = 0.0;
qv4_temp2 = 0.0;
qv1_temp3 = 0.0;
qv2_temp3 = 0.0;
qv3_temp3 = 0.0;
qv4_temp3 = 0.0;
}
void Quaternion::Normalize()
{
double norm2 = q1*q1 + q2*q2 + q3*q3 + q4*q4;
double norm = sqrt(norm2);
if(norm > 0.0)
{
q1 = q1/norm;
q2 = q2/norm;
q3 = q3/norm;
q4 = q4/norm;
}
else
{
cout << "q= " << q1 << ", " << q2 << ", " << q3 << ", " << q4 << endl;
cout << "qv=" << qv1 << ", " << qv2 << ", " << qv3 << ", " << qv4 << endl;
cout << "qa=" << qa1 << ", " << qa2 << ", " << qa3 << ", " << qa4 << endl;
system("pause");
}
}
Quaternion Quaternion::operator *(const Quaternion &a) const
{
Quaternion result;
result.q4 = q4*a.q4 - q1*a.q1 - q2*a.q2 - q3*a.q3;
result.q1 = q4*a.q1 + q1*a.q4 + q3*a.q2 - q2*a.q3;
result.q2 = q4*a.q2 + q2*a.q4 + q1*a.q3 - q3*a.q1;
result.q3 = q4*a.q3 + q3*a.q4 + q2*a.q1 - q1*a.q2;
return result;
}
Quaternion& Quaternion::operator *=(const Quaternion &a)
{
// Multuiply and assign
*this = *this * a;
// Return reference to l-value
return *this;
}
Quaternion Difference(Quaternion temp, Quaternion qua)
{
Quaternion temp_inverse = Conjugate(temp);
//Quaternion difference = qua * temp_inverse; /////
Quaternion difference = temp_inverse * qua;
return difference;
}
Quaternion Conjugate(const Quaternion &q)
{
Quaternion result;
// Same rotation amount
result.q4 = q.q4;
// Opposite axis of rotation
result.q1 = -q.q1;
result.q2 = -q.q2;
result.q3 = -q.q3;
// Return it
return result;
}
void W_Matrix(vector<vector<double> > &w, Quaternion qua)
{
w[0][0] = qua.q4;
w[0][1] = qua.q3;
w[0][2] = -qua.q2;
w[0][3] = -qua.q1;
w[1][0] = -qua.q3;
w[1][1] = qua.q4;
w[1][2] = qua.q1;
w[1][3] = -qua.q2;
w[2][0] = qua.q2;
w[2][1] = -qua.q1;
w[2][2] = qua.q4;
w[2][3] = -qua.q3;
w[3][0] = qua.q1;
w[3][1] = qua.q2;
w[3][2] = qua.q3;
w[3][3] = qua.q4;
}
void W_Transverse(vector<vector<double> > &wt, Quaternion qua)
{
wt[0][0] = qua.q4;
wt[0][1] = -qua.q3;
wt[0][2] = qua.q2;
wt[0][3] = qua.q1;
wt[1][0] = qua.q3;
wt[1][1] = qua.q4;
wt[1][2] = -qua.q1;
wt[1][3] = qua.q2;
wt[2][0] = -qua.q2;
wt[2][1] = qua.q1;
wt[2][2] = qua.q4;
wt[2][3] = qua.q3;
wt[3][0] = -qua.q1;
wt[3][1] = -qua.q2;
wt[3][2] = -qua.q3;
wt[3][3] = qua.q4;
}
------------------------------------------------------------------------------
#ifndef VECTOR3_H
#define VECTOR3_H
#include <iostream>
#include <cmath>
class Vector3
{
public:
double x, y, z;
Vector3 (double v1, double v2, double v3):x(v1),y(v2),z(v3){}
Vector3 (){x=0.0; y=.0; z=0.0;}
double magnitude();
double magnitude2();
Vector3 operator+ (const Vector3 &v2);
Vector3 operator- (const Vector3 &v2);
Vector3 operator* (const double n);
Vector3 operator/ (const double n);
Vector3& operator= (const Vector3 u);
Vector3& operator+=(const Vector3 u);
Vector3& operator-=(const Vector3 u);
Vector3& operator*=(const double n);
void normalize();
friend double Dot(Vector3 v1, Vector3 v2);
friend Vector3 Cross(Vector3 &u, Vector3 &v);
};
extern const Vector3 ZeroVector;
extern const Vector3 Nx;
extern const Vector3 Ny;
extern const Vector3 Nz;
#endif // #ifndef VECTOR3_H
------------------------------------------------------------------------------
#include "Vector3.h"
extern const Vector3 ZeroVector(0.0, 0.0, 0.0);
extern const Vector3 Nx(1.0, 0.0, 0.0);
extern const Vector3 Ny(0.0, 1.0, 0.0);
extern const Vector3 Nz(0.0, 0.0, 1.0);
double Vector3::magnitude()
{
double v = sqrt(x*x + y*y + z*z);
return v;
}
double Vector3::magnitude2()
{
return x*x + y*y + z*z;
}
Vector3 Vector3::operator+(const Vector3 &v2)
{
Vector3 v;
v.x = this->x + v2.x;
v.y = this->y + v2.y;
v.z = this->z + v2.z;
return v;
}
Vector3 Vector3::operator-(const Vector3 &v2)
{
Vector3 v;
v.x = this->x - v2.x;
v.y = this->y - v2.y;
v.z = this->z - v2.z;
return v;
}
Vector3 Vector3::operator*(const double n)
{
Vector3 u;
u.x = this->x*n;
u.y = this->y*n;
u.z = this->z*n;
return u;
}
Vector3 Vector3::operator/(const double n)
{
Vector3 u;
u.x = this->x/n;
u.y = this->y/n;
u.z = this->z/n;
return u;
}
Vector3& Vector3::operator=(const Vector3 u)
{
this->x = u.x;
this->y = u.y;
this->z = u.z;
return *this;
}
Vector3& Vector3::operator+=(const Vector3 u)
{
*this = *this + u;
return *this;
}
Vector3& Vector3::operator-=(const Vector3 u)
{
*this = *this - u;
return *this;
}
Vector3& Vector3::operator*=(const double n)
{
*this = *this * n;
return *this;
}
void Vector3::normalize()
{
double norm = this->magnitude();
//if (norm == 0.0)
//{
// x = 0.0; y = 0.0; z = 0.0;
//}
//else
//{
x = x/norm; // 可能會blow up!!!
y = y/norm;
z = z/norm;
//}
}
double Dot(Vector3 v1, Vector3 v2)
{
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
}
Vector3 Cross(Vector3 &u, Vector3 &v)
{
Vector3 w;
w.x = u.y * v.z - u.z * v.y;
w.y = u.z * v.x - u.x * v.z;
w.z = u.x * v.y - u.y *v.x;
return w;
}
------------------------------------------------------------------------------
#ifndef FUNDMATH_H
#define FUNDMATH_H
#include <cmath>
#include <iostream>
const double PI = 3.14159265;
double sign(double a, double b);
double max (double a, double b);
double min (double a, double b);
void SinCos(double *returnSin, double *returnCos, double theta);
#endif // #ifndef FUNDMATH_H
------------------------------------------------------------------------------
#include <cstdlib>
#include <ctime>
#include "FundMath.h"
double sign(double a, double b)
{
if (b >= 0.0)
return abs(a);
else
return -1*abs(a);
}
double max(double a, double b)
{
if (a >= b) return a;
else return b;
}
double min(double a, double b)
{
if (a<=b) return a;
else return b;
}
void SinCos(double *returnSin, double *returnCos, double theta)
{
*returnSin = sin(theta);
*returnCos = cos(theta);
}
※ 編輯: luckychild 來自: 140.120.11.75 (03/17 17:14)
推
03/17 16:59, , 9F
03/17 16:59, 9F
→
03/17 17:00, , 10F
03/17 17:00, 10F
※ 編輯: luckychild 來自: 140.120.11.75 (03/17 17:18)
※ 編輯: luckychild 來自: 140.120.11.75 (03/17 17:19)
→
03/17 17:20, , 11F
03/17 17:20, 11F
→
03/17 17:39, , 12F
03/17 17:39, 12F
→
03/17 17:42, , 13F
03/17 17:42, 13F
→
03/17 17:42, , 14F
03/17 17:42, 14F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章