views:

93

answers:

3

What do these errors mean?

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)’

The C++ (Line 13 is the 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

The header file:

#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 */
+4  A: 

Constructors have no return type, not even void. Just remove the void and you're fine.

Alexander Gessler
That is what I originally had and it adds another error.
Josh Curren
Then maybe you should ask about that other error.
David Rodríguez - dribeas
Try GMan's suggestion, also make sure you have the c'tor declared in the class (`Vector(double x,double y,double z);` somewhere in the declaration of `Vector`).
Alexander Gessler
I added the second error to the question
Josh Curren
Some of your operators return bool, but the should return `Vector`.
Alexander Gessler
Also, you need to rename your namespace (using the same name as for the class leeds to disambiguities).
Alexander Gessler
+2  A: 

Looks like the major problem is that your cpp files didn't include your header file.

leiz
+1  A: 

Include the header file in the cpp file. Also, the code has some design issues. operator+ should return const Vector and the same case with operator-.

Jagannath