Hi,
I am a Java developper, and now I'm trying to learn C++. I'm very new to the programming language. I'm trying to pass objects to a constructor, which I appear to be doing wrong.
A triangle-object needs to contain references to 3 "Vertex" objects, which are the points of the triangle.
Triangle.h
Triangle.cpp
Vertex.h
The above code generates the error "Triangle.cpp:1 3:63: error: no matching function for call to 'geometry::Vert ex::Vertex()' note: candidates are: geometry::Verte x::Vertex(float , float, float)",
among others.
My interpretation is that C++ tries to create the vertex-objects in the call to Triangle::Trian gle(Vertex & one, Vertex & two, Vertex & three) with only this code, whereas I simply want to have one, two and three as placeholders for passed objects when I'm actually using the constructor, like I would have in java.
As you can see, I am an absolute beginner at C++.
What am I doing wrong?
Thanks
I am a Java developper, and now I'm trying to learn C++. I'm very new to the programming language. I'm trying to pass objects to a constructor, which I appear to be doing wrong.
A triangle-object needs to contain references to 3 "Vertex" objects, which are the points of the triangle.
Triangle.h
Code:
#ifndef TRIANGLE_H_ #define TRIANGLE_H_ #include "Vertex.h" namespace geometry { class Triangle { public: Vertex v1,v2,v3; Triangle(Vertex & one, Vertex & two, Vertex & three); virtual ~Triangle(); }; } #endif /* TRIANGLE_H_ */
Code:
... Triangle::Triangle(Vertex & one, Vertex & two, Vertex & three) { v1 = one; v2 = two; v3 = three; } ...
Code:
#ifndef VERTEX_H_ #define VERTEX_H_ #include "../algebra/Vector4f.h" #include "../algebra/Matrix4f.h" using namespace algebra; namespace geometry { class Vertex { public: Vector4f position; Vertex(float x, float y, float z); float x(); float y(); float z(); void transform(Matrix4f& m); virtual ~Vertex(); }; } #endif /* VERTEX_H_ */
among others.
My interpretation is that C++ tries to create the vertex-objects in the call to Triangle::Trian gle(Vertex & one, Vertex & two, Vertex & three) with only this code, whereas I simply want to have one, two and three as placeholders for passed objects when I'm actually using the constructor, like I would have in java.
As you can see, I am an absolute beginner at C++.
What am I doing wrong?
Thanks
Comment