我的矢量程序错误... [英] error in my vector program...

查看:58
本文介绍了我的矢量程序错误...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我用g ++得到这个:


main.cpp:9:错误:新类型可能没有定义一个返回类型

main.cpp:9:注意:(定义后可能缺少分号
$'$ b''''''''''$ $ $ $ $ $ b main.cpp:9:错误:''set''声明中有两个或更多数据类型


我真的没有看到问题......这里是代码:


----------

#include< iostream>

using namespace std ;


struct vector

{

double x,y,z;

}


void set(vector& v,double x1,double y1,double z1)

{

vx = x1; v.y = y1; vz = z1;

}


虚度(矢量& v,双k)

{

vx * = k; v.y * = k; vz * = k;

}


双内(矢量a,矢量b)

{

返回ax * bx + a。 y * by + az * bz;

}


无效打印(矢量v)

{

cout<< Vector("<<< v.x<<"""<<<<<<<<<<<<<<<<<<<<<<<<<""<<< v.z<<"")" <<结束;

}


int main()

{

vector v1;

vector v2;

set(v1,1.1,2.2,3.3);

v2 = v1;

scale(v2 ,2);

print(v1); print(v2);

cout<< 内部产品= <<内(v1,v2);

}

--------------

祝你好运/ Med venlig hilsen

Martin J?rgensen


-

-------------- -------------------------------------------------- -----------

Martin J?rgensen的家 - http://www.martinjoergensen.dk

解决方案

" Martin J?rgensen"写道:

我使用g ++得到这个:

main.cpp:9:错误:可能无法在返回类型中定义新类型
main.cpp:9:注意:(可能在定义
''vector'后缺少分号)
main.cpp:9:错误:两个或多个数据类型声明''设置''

我真的没有看到问题......这里是代码:

-------- -
#include< iostream>
使用命名空间std;

struct vector
{
double x,y,z;
}




缺少分号。一直发生。


< snip>


Martin J?rgensen skrev:



我用g ++得到这个:

main.cpp:9:错误:新类型可能没有在返回类型中定义
main.cpp: 9:注意:(在''vector''的定义之后可能缺少分号)
main.cpp:9:错误:声明''set''中的两个或多个数据类型

我真的没有看到问题......这是代码:

----------
#include < iostream>
使用命名空间std;

struct vector
{
双x,y,z;
}



" main.cpp:9:注意:(可能是分号丢失......


struct vector

{

双x,y,z;

};


< snip>

-

TB @ SWEDEN


osmium写道:

Martin J?rgensen写道:

我使用g ++得到这个:

main.cpp:9:错误:可能无法在返回类型中定义新类型
main.cpp:9:注意:(可能在定义
''vector'后缺少分号)
main.cpp:9:错误:声明''中的两个或多个数据类型设置''

我真的没有看到问题......这是代码:

----------
#include< iostream>
使用命名空间std;

struct vector
{
double x,y,z;
}


缺少分号。一直都在发生。

< snip>




非常感谢你们两个......我专注于9+行但是我应该看看第7行
。猜猜我会因为更多经验而变得更好......

祝你好运/ Med venlig hilsen

Martin J?rgensen


-

---------------------- -------------------------------------------------- ---

Martin J?rgensen的家 - http:// www。 martinjoergensen.dk


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);
}
--------------
Best regards / Med venlig hilsen
Martin J?rgensen

--
---------------------------------------------------------------------------
Home of Martin J?rgensen - http://www.martinjoergensen.dk

解决方案

"Martin J?rgensen" writes:

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;
}



Missing semicolon. Happens all the time.

<snip>


Martin J?rgensen skrev:

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;
}



"main.cpp:9: note: (perhaps a semicolon is missing ..."

struct vector
{
double x, y, z;
};

<snip>
--
TB @ SWEDEN


osmium wrote:

"Martin J?rgensen" writes:

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;
}


Missing semicolon. Happens all the time.

<snip>



Thanks a lot, both of you... I was focusing on lines 9+ but I should
have looked at line 7. Guess I''ll become better with more experience...
Best regards / Med venlig hilsen
Martin J?rgensen

--
---------------------------------------------------------------------------
Home of Martin J?rgensen - http://www.martinjoergensen.dk


这篇关于我的矢量程序错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆