不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误
来源:互联网 发布:淘宝店铺流量是什么 编辑:程序博客网 时间:2024/06/06 08:45
不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误
我在VS2005中编译Vector3D类出现
error C2662: “Vector3D::dotP”: 不能将“this”指针从“const Vector3D”转换为“Vector3D &”
怎么样改正呢,这个类也是看到别人这样写的,编译也没有错误。
#pragma once
#define M_PI 3.141
#include <math.h>
class Vector3D{
Vector3D(){x=y=z=0.0;}
Vector3D(double vx, double vy,double vz=0.0){
x = vx;
y = vy;
z = vz;
}
double magnitude() const{
return sqrt(x*x+y*y+z*z);
}
double dotP(const Vector3D& v1,const Vector3D& v2){
return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);
}
// get the vector angle
double angle() const{
double ret = 0.0;
double m = magnitude();
if (m>1.0e-6) {
// 问题出在这里!!!!
// ==============================
double dp = dotP(*this,Vector3D(1.0,0.0));
//==============================
if (dp/m>=1.0) {
ret = 0.0;
}
else if (dp/m<-1.0) {
ret = M_PI;
}
else {
ret = acos( dp / m);
}
if (y<0.0) {
ret = 2*M_PI - ret;
}
}
return ret;
}
protected:
double x;
double y;
double z;
};#pragma once
#define M_PI 3.141
#include <math.h>
class Vector3D{
Vector3D(){x=y=z=0.0;}
Vector3D(double vx, double vy,double vz=0.0){
x = vx;
y = vy;
z = vz;
}
double magnitude() const{
return sqrt(x*x+y*y+z*z);
}
double dotP(const Vector3D& v1,const Vector3D& v2){
return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);
}
// get the vector angle
double angle() const{
double ret = 0.0;
double m = magnitude();
if (m>1.0e-6) {
double dp = dotP(*this,Vector3D(1.0,0.0));
if (dp/m>=1.0) {
ret = 0.0;
}
else if (dp/m<-1.0) {
ret = M_PI;
}
else {
ret = acos( dp / m);
}
if (y<0.0) {
ret = 2*M_PI - ret;
}
}
return ret;
}
protected:
double x;
double y;
double z;
};
posted on 2006-05-10 14:42 Beginning to 编程 阅读(791) 评论(2) 编辑 收藏 引用 所属分类: 关键代码
评论
# re: 不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误2006-05-10 21:50史传红
原因不是*this不能转换成const vector3D&,而是常成员函数(double angle() const)不能调用 非常成员函数(double dotP(const Vector3D& v1,const Vector3D&v2)),如果把dotp改成如下定义:double dotP(const Vector3D& v1,constVector3D& v2) const.
问题就解决了. 回复 更多评论
# re: 不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误2006-05-11 11:59nico
double dotP(const Vector3D& v1,const Vector3D& v2) const
{
return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);
}
回复 更多评论
- 不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误
- Vector3d
- 不能将this指针从“const type" 转换为"type &"
- 不能将“this”指针从“const Vehicle”转换为“Vehicle &”
- 不能将“this”指针从“const CPaopao”转换为“CPaopao &
- 不能将“this”指针从“const Class(某个类)”转换为“Class &" 错误
- error C2662: 不能将“this”指针从“const Node_align”转换为“Node_align &”解决方案
- error C2662: “CMaDirOperation::chang_file_type”: 不能将“this”指针从“const CMaDirOperation”转换为“CMaDirOperat
- error C2662: “int Fraction::numerator(void)”: 不能将“this”指针从“const Fraction”转换为“Fraction &”
- 【C++】不能将“this”指针从“const vector”转换为“vector & rhs"
- 对象引用前加const报错:不能将“this”指针从“const a”转换为“a
- 对象引用前加const报错:不能将“this”指针从“const a”转换为“a
- 对象引用前加const报错:不能将“this”指针从“const a”转换为“a
- 对象引用前加const报错:不能将“this”指针从“const a”转换为“a
- c++;对象引用前加const报错:不能将“this”指针从“const a”转换为“a &”
- [error] MFC错误不能将参数1从"const char [3]"转换为"const wchar_t *"
- 不能将“this”指针从“const XXX”转为“XXX &”
- C++ error C2662: “LinkNode<T> *List<T>::Locate(int)”: 不能将“this”指针从“const List<int>”转换为“List<int> &”
- 这辈子只跟老婆做的50件事
- break和continue的用法
- JAVA手机软件程序JAR文件和JAD文件详解
- 临时表在Oracle数据库与SQL Server数据库中的异同
- axis webservice 的实现原理
- 不能将“this”指针从“const Vector3D”转换为“Vector3D &" 错误
- (转)ClearCase四大功能详述(版本控制)
- 运行java时,窗体在屏幕中间显示的代码
- Struts2的工作原理
- directdraw上画边框矩形
- AjaxControltoolkit学习笔记—AlwaysVisibleControlExtender使用详解
- 华诚管理培训随笔
- 面向对象
- Struts 2详细工作流程