470,564 Members | 2,413 Online

# Construct a Vector by subtracting 2 verticies 2 2Bits
For my assignment, I need to construct a function that takes 2 vertices(any vertex), subtract them and return a vector
The vertices are defined in the Vertex class and the vectors in Vector3D class

Screenshot_216.png
Screenshot_217.png

I put the declaration of the function in the Vertex header (and her body in the Vertex class) because it needs to be called from the vertices

Expand|Select|Wrap|Line Numbers
1.   // The decleration in the Vertex header
2.
3.         Vector3D VecSub(Vertex const &other);
4.
5.
6.         //The body in the Vertex Class
7.
8.         Vector3D Vertex::VecSub(Vertex const &other)
9.
10.         {
11.         Vertex a;
12.         Vertex b;
13.         Vertex sub = a - b;
14.         Vector3D temp(sub.GetX(), sub.GetY(), sub.GetZ());;
15.         return temp;
16.         }
17.
18.
19.         //The use of the function in the model class
20.
21.         Vector3D vectorA = vertex1.VecSub(vertex0);
22.         Vector3D vectorB = vertex2.VecSub(vertex0);
23.
24.         Vector3D EyeVector =
25.         vertex0.VecSub(camera.GetPos());

When I debug the program I am getting this errors
Screenshot_215.jpg

The declaration of 'Vertex'

Expand|Select|Wrap|Line Numbers
1. Vertex(float x, float y, float z, float w);

And the declaration of 'Vertex3D

Expand|Select|Wrap|Line Numbers
1. Vector3D(float x, float y, float z);
`
Attached Images Screenshot_216.png (3.6 KB, 25 views) Screenshot_217.png (1.9 KB, 25 views) Screenshot_215.jpg (83.5 KB, 30 views)
Feb 8 '21 #1

OK does Vector3D.h include Vertex.h (or stdafx.h)? Circular inclusion tends to lead to strange errors.

This compiles fine if comment out the include stdafx.h and create my own Vector3D,h like so
Expand|Select|Wrap|Line Numbers
1. #pragma once
2.
3. class Vector3D
4. {
5.   public:
6.     Vector3D() {}
7.     virtual ~Vector3D() {}
8. };
9.

3 1952 Banfa
9,065 Expert Mod 8TB
It looks like you have not shown us the actual code causing the error, 1 line from a header file isn't really enough, I assume that line 3 of the posted code is actually line 31 of Vertex.h.

What the error is telling you, in a rather obtuse way, is that it doesn't know what Vector3D is at this point. An override specifier is some combination of the keywords `override` or `final` that should appear at the end of the function definition.

It appears likely that you have used the Vector3D type without including the header file that defines it.
Feb 9 '21 #2
Eldyr
2 2Bits
I have included the Vector3D.h to the Vertex header

Expand|Select|Wrap|Line Numbers
1. #pragma once
2. #include "Vector3D.h"
3. #include "stdafx.h"
4.
5. class Vertex
6. {
7. public:
8.     Vertex();
9.     Vertex(float x, float y, float z, float w);
10.
11.     //Copy constructor
12.     Vertex(const Vertex& v);
13.
14.     //Destructor
15.     ~Vertex();
16.
17.     //Accessors and mutators
18.     float GetX() const;
19.     int GetIntX() const;
20.     void SetX(const float x);
21.     float GetY() const;
22.     int GetIntY() const;
23.     void SetY(const float y);
24.     float GetZ() const;
25.     void SetZ(const float z);
26.     float GetW() const;
27.     void SetW(const float w);
28.
29.     void Dehomogenize();
30.
31.
32.         Vector3D VecSub(Vertex const &other);
33.
34.     //Assignment operator
35.     Vertex& operator= (const Vertex& rhs);
36.
37.     bool operator== (const Vertex& rhs) const;
38.
39.     const Vertex operator+ (const Vertex& rhs) const;
40.
41.     const Vertex operator- (const Vertex& rhs) const;
42.
43.
44. private:
45.     float _x;
46.     float _y;
47.     float _z;
48.     float _w;
49.
50. };
Feb 9 '21 #3
Banfa
9,065 Expert Mod 8TB
OK does Vector3D.h include Vertex.h (or stdafx.h)? Circular inclusion tends to lead to strange errors.

This compiles fine if comment out the include stdafx.h and create my own Vector3D,h like so
Expand|Select|Wrap|Line Numbers
1. #pragma once
2.
3. class Vector3D
4. {
5.   public:
6.     Vector3D() {}
7.     virtual ~Vector3D() {}
8. };
9.
Feb 10 '21 #4