Hi Guys, I'm working on fixing a program as part of my C++ Course. I have been trying for 4 days now and I'm getting no where. As soon as I change something I get more errors and I'm starting to get fed up now (I'm usually very patient when it comes to testing something out).
Here is the code
// This program reads in three x/y/z coordinates and save them into Vector3 instances.
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::cin;
using std::endl;
class Vector3
{
private:
float x;
float y;
float z;
// Others
void print()
{
cout << x << y << z << endl;
}
}
int main()
{
// Only need to declare three floats for storage, we can reuse them for each
// vector input.
float in0;
float in1;
float in2;
Vector3 v0;
Vector3 v1;
Vector3 v2;
// Read first coordinate
cout << "Input coords for the first vertex (separated by spaces): ";
cin >> in0 >> in1 >> in2;
v0 = Vector3(in0, in1, in2);
// Read second coordinate, and set second triangle vertex
cout << "Input coords for the second vertex (separated by spaces): ";
cin >> in0 >> in1 >> in2;
v1 = Vector3(in0, in1, in2);
// Read third coordinate, and set third triangle vertex
cout << "Input coords for of the third vertex (separated by spaces): ";
cin >> in0 >> in1 >> in2;
v2 = Vector3(in0, in1, in2);
// Print a blank line, then the coordinates
cout << endl;
v0.print();
v1.print();
v2.print();
return 0;
}
AND HERE IS THE ERROR MESSAGE THAT IT CHUCKS OUT. I'M USING VISUAL STUDIO 2010 PROFESSIONAL
main.cpp(24): error C2059: syntax error : '{'
main.cpp(24): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
main.cpp(50): error C2628: 'Vector3' followed by 'int' is illegal (did you forget a ';'?)
main.cpp(51): error C3874: return type of 'main' should be 'int' instead of 'Vector3'
hold on, I've done what you said. Sorry I didn't realise I had to put the semi colon right at the end, after I've listed the class definitions. So now it's
class Vector3
{
private:
float x;
float y;
float z;
public:
// Constructors/Destructors
Vector3 (float xval = 0, float yval = 0, float zval = 0);
{
x = xVal;
y = yVal;
z = zVal;
};
Good news, I've now gotten it down to only two errors
main.cpp(24): error C2059: syntax error : '{'
main.cpp(24): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
I will check the braces now, however, because I have been doing this for four days straight I must have already done that. But I will do it again just to check.
If you could shed some light on those two errors above.