gpt4 book ai didi

C++ 错误 : explicit qualification

转载 作者:搜寻专家 更新时间:2023-10-31 00:05:30 25 4
gpt4 key购买 nike

这些错误是什么意思?

Vector.cpp:13: error: ISO C++ forbids declaration of ‘Vector’ with no type
Vector.cpp:13: error: explicit qualification in declaration of ‘void Vector::Vector(double, double, double)’

C++(第 13 行是 Vector::Vector( ...):

#include <iostream>
using namespace std;

namespace Vector
{
Vector::Vector( double x, double y, double z)
{
a = x;
b = y;
c = z;
}
/*
double Vector::dot(const Vector &v) const
{
return (a*v.a)+(b*v.b)+(c*v.c);
}
*/
Vector Vector::operator+(const Vector &v) const
{
Vector v1( a + v.a, b + v.b, c + v.c );
return v1;
}

Vector Vector::operator-(const Vector &v) const
{
Vector v1( a - v.a, b - v.b, c - v.c );
return v1;
}

bool Vector::operator==(const Vector &v) const
{
if( (a == v.a) && (b == v.b) && (c == v.c) )
{
return true;
}
else
{
return false;
}
}

Vector Vector::operator*(const Vector &v) const
{
Vector v1( b*v.c - c*v.b, c*v.a - a*v.c, a*v.b - b*v.a );
return v1;
}

ostream& operator<<(ostream &out, const Vector &v)
{
out << "<" << v.a << ", " << v.b << ", " << v.c << ">";
return out;
}

istream& operator>>(istream &in, Vector &v)
{
in >> v.a;
in >> v.b;
in >> v.c;
return in;
}
/*
double length( Vector v )
{
return sqrt( (v.a*v.a)+(v.b*v.b)+(v.c*v.c) );
}
*/
} // end namespace Vector

头文件:

#ifndef _VECTOR_H
#define _VECTOR_H

#include <cstdlib>
#include <iostream>

using namespace std;

namespace Vector
{


class Vector
{
private:
double a;
double b;
double c;

public:
Vector( double x=0.0, double y=0.0, double z=0.0);

double dot(const Vector &v) const;
Vector operator+(const Vector &v) const;
Vector operator-(const Vector &v) const;
bool operator==(const Vector &v) const;
Vector operator*(const Vector &v) const;
friend ostream& operator<<(ostream &out, const Vector &v);
friend istream& operator>>(istream &in, Vector &v);


}; // end Vector class

double length(Vector v);

} //end namespace Vector
#endif /* _VECTOR_H */

最佳答案

构造函数没有返回类型,甚至没有 void。只需删除 void 即可。

关于C++ 错误 : explicit qualification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2215250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com