Het zal wel superstom zijn, maar ik kom er gewoon niet uit. (Ik ben c++ newbie). Ik heb de volgende headerfile:
Nu wil ik matrix1 met matrix2 vermenigvuldigen:
Maar dat mag dus niet:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
| #ifndef VECTOR_H
#define VECTOR_H
/****************************************************************
*
* vector.h
*
* Author: M.R.Nederlof
* Date: August 1999
* Project: in3023 - 3D Computer Graphics and Virtual Reality
* Programming Assignment
*
****************************************************************/
#include <glut.h>
class Vec3
{
public:
GLdouble x, y, z;
Vec3 ();
Vec3 (GLdouble _x, GLdouble _y, GLdouble _z);
Vec3 (const Vec3& v);
Vec3 (GLdouble *v);
Vec3 &Set (GLdouble _x, GLdouble _y, GLdouble _z);
Vec3 &Set (const Vec3& v);
Vec3 &Set (GLdouble *v);
Vec3& Add (const Vec3& a);
Vec3& Sub (const Vec3& a);
Vec3& Mul (const Vec3& a);
Vec3& Div (const Vec3& a);
Vec3& Cross (const Vec3& a);
Vec3& Scale (GLdouble factor);
Vec3& Normalize ();
GLdouble Length () const;
GLdouble Dot (const Vec3& a) const;
GLdouble Distance (const Vec3& v) const;
void Print (const char *text="") const;
static Vec3 Add (const Vec3& a, const Vec3& b);
static Vec3 Sub (const Vec3& a, const Vec3& b);
static Vec3 Mul (const Vec3& a, const Vec3& b);
static Vec3 Div (const Vec3& a, const Vec3& b);
static Vec3 Cross (const Vec3& a, const Vec3& b);
static Vec3 Scale (const Vec3& a, GLdouble factor);
static Vec3 Normalize (const Vec3& a);
Vec3& operator= (const Vec3& other) { return Set(other); }
};
class Vec4
{
public:
GLdouble x, y, z, w;
Vec4 ();
Vec4 (GLdouble _x, GLdouble _y, GLdouble _z, GLdouble _w);
Vec4 (const Vec4& v);
Vec4 (GLdouble *v);
Vec4& Set (GLdouble _x, GLdouble _y, GLdouble _z, GLdouble _w);
Vec4& Set (const Vec4& v);
Vec4& Set (GLdouble *v);
Vec4& Add (const Vec4& a);
Vec4& Sub (const Vec4& a);
Vec4& Mul (const Vec4& a);
Vec4& Div (const Vec4& a);
Vec4& Scale (GLdouble factor);
Vec4& Normalize ();
GLdouble Length () const;
GLdouble Distance (const Vec4& v) const;
void Print (const char *text="") const;
static Vec4 Add (const Vec4& a, const Vec4& b);
static Vec4 Sub (const Vec4& a, const Vec4& b);
static Vec4 Mul (const Vec4& a, const Vec4& b);
static Vec4 Div (const Vec4& a, const Vec4& b);
static Vec4 Cross (const Vec4& a, const Vec4& b);
static Vec4 Scale (const Vec4& a, GLdouble factor);
static Vec4 Normalize (const Vec4& a);
Vec4& operator= (const Vec4& other) { return Set(other); }
};
class Matrix4
{
public:
GLdouble element[16];
Matrix4 ();
Matrix4 (const Matrix4& m);
Matrix4 (const GLdouble *m);
Matrix4 (const GLdouble **m);
Matrix4 (GLdouble m11, GLdouble m21, GLdouble m31, GLdouble m41,
GLdouble m12, GLdouble m22, GLdouble m32, GLdouble m42,
GLdouble m13, GLdouble m23, GLdouble m33, GLdouble m43,
GLdouble m14, GLdouble m24, GLdouble m34, GLdouble m44);
Matrix4& Set (const Matrix4& m);
Matrix4& Set (const GLdouble *m);
Matrix4& Set (const GLdouble **m);
Matrix4& Set (GLdouble m11, GLdouble m21, GLdouble m31, GLdouble m41,
GLdouble m12, GLdouble m22, GLdouble m32, GLdouble m42,
GLdouble m13, GLdouble m23, GLdouble m33, GLdouble m43,
GLdouble m14, GLdouble m24, GLdouble m34, GLdouble m44);
Matrix4& Identity ();
Matrix4& Transpose ();
Matrix4& Multiply (const Matrix4& m);
Vec4 MultiplyByPoint (const Vec4& v);
void Print (const char *text="") const;
static Matrix4 Transpose (const Matrix4& m);
static Matrix4 Multiply (const Matrix4& m1, const Matrix4& m2);
static Vec4 MultiplyByPoint (const Vec4& v, const Matrix4& m);
};
#endif // VECTOR_H |
Nu wil ik matrix1 met matrix2 vermenigvuldigen:
code:
1
2
3
4
| Matrix4 *m1 = new Matrix4(); Matrix4 *m2 = new Matrix4(); m1->Multiply(m2); |
Maar dat mag dus niet:
Wat doe ik fout?error C2664: 'class Matrix4 &__thiscall Matrix4::Multiply(const class Matrix4 &)' : cannot convert parameter 1 from 'class Matrix4 *' to 'const class Matrix4 &'
Reason: cannot convert from 'class Matrix4 *' to 'const class Matrix4'
No constructor could take the source type, or constructor overload resolution was ambiguous