Input 3 vectors. Error codes: C2059, C2334, C2628 & C3874,

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;

public:

// Constructors/Destructors
Vector3 (float xval = 0, float yval = 0, float zval = 0);
{
};

~Vector3()
{
// empty for now
}


// Accessors
float getX() {return x;}
float getY() {return y;}
float getZ() {return z;}

// Mutators
void setX(float xval) {x = xval; return;}
void setY(float yval) {y = yval; return;}
void setZ(float zval) {z = zval; return;}

// 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'


You need a ; at the end of your class definitions.
So that'll just be class Vector3 then a semicolon? I.e class vector3;

I have tried that but I am still getting the same error messages.
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.

Many Thanks =)
Last edited on
You have a trailing ; after the constructor's parameter list.
You also have an extra ; after the body.

In the future, please use [code][/code] tags to make your code easier to read; it also preserves indentation.
Topic archived. No new replies allowed.