?
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
Hi,
I get this using g++:
main.cpp:9: error: new types may not be defined in a return type
main.cpp:9: note: (perhaps a semicolon is missing after the definition
of 'vector')
main.cpp:9: error: two or more data types in declaration of 'set'
I don't really see the problem... Here's the code:
----------
#include <iostream>
using namespace std;
struct vector
{
double x, y, z;
}
void set(vector & v, double x1, double y1, double z1)
{
v.x = x1; v.y = y1; v.z = z1;
}
void scale(vector & v, double k)
{
v.x *= k; v.y *=k; v.z *=k;
}
double inner(vector a, vector b)
{
return a.x * b.x + a. y * b.y + a.z * b.z;
}
void print(vector v)
{
cout << "Vector(" << v.x << ", " << v.y << ", " << v.z << ")" << endl;
}
int main()
{
vector v1;
vector v2;
set(v1, 1.1, 2.2, 3.3);
v2=v1;
scale(v2, 2);
print(v1); print(v2);
cout << "Inner product = " << inner(v1, v2);
}
I get this using g++:
main.cpp:9: error: new types may not be defined in a return type
main.cpp:9: note: (perhaps a semicolon is missing after the definition
of 'vector')
main.cpp:9: error: two or more data types in declaration of 'set'
I don't really see the problem... Here's the code:
----------
#include <iostream>
using namespace std;
struct vector
{
double x, y, z;
}
void set(vector & v, double x1, double y1, double z1)
{
v.x = x1; v.y = y1; v.z = z1;
}
void scale(vector & v, double k)
{
v.x *= k; v.y *=k; v.z *=k;
}
double inner(vector a, vector b)
{
return a.x * b.x + a. y * b.y + a.z * b.z;
}
void print(vector v)
{
cout << "Vector(" << v.x << ", " << v.y << ", " << v.z << ")" << endl;
}
int main()
{
vector v1;
vector v2;
set(v1, 1.1, 2.2, 3.3);
v2=v1;
scale(v2, 2);
print(v1); print(v2);
cout << "Inner product = " << inner(v1, v2);
}