菜鸟遇到菜问题哭了,帮帮忙把

ryam1126 2008-04-18 12:47:44
以下是我按着一本书的代码打的,有47个错误,我看了几个小时没看出错在那
#pragma once
#include<iostream>
#include<string>
#include<queue>
using namespace std;

class Weapon()
{
private:
string _name;
int _power;
public:
Weapon();
Weapon(char name,int power);
string GetName();
int GetPower();
bool operator < (const Weapon &other) const;
bool operator > (const Weapon &other) const;
};
typedef priority_queue< Weapon,vector<Weapon> >Weapons;
//对流的操作支持
ostream &operator<<(osteam &cout,Weapon &weapon);





#include"Weapon.h"

using namespace std;

//让Weapon支持流的操作
ostream &operator<<(ostream &cout,Weapon &weapon)
{
cout<<weapon.getName()<<"("<<weapon.getPower()<<")";
return cout;
}
Weapon::Weapon()
{ }
Weapon::weapon(string name,int power):_name(name),_power(power)
{ }
string weapon::GetName()
{ return _name; }

int weapon::GetPower()
{ return _power; }

bool weapon::operator <(const Weapon &other) const
{
return this->_power < other._power;
}
bool weapon::operator >(const Weapon &other) const
{
return this->_power > other._power;
}




:\msdev98\myprojects\西游记\weapon.h(9) : error C2143: syntax error : missing ';' before 'private'
e:\msdev98\myprojects\西游记\weapon.h(12) : error C2143: syntax error : missing ';' before 'public'
e:\msdev98\myprojects\西游记\weapon.h(14) : error C2144: syntax error : missing ')' before type 'char'
e:\msdev98\myprojects\西游记\weapon.h(14) : error C2059: syntax error : ')'
e:\msdev98\myprojects\西游记\weapon.h(17) : error C2143: syntax error : missing ',' before '&'
e:\msdev98\myprojects\西游记\weapon.h(17) : error C2059: syntax error : '&'
e:\msdev98\myprojects\西游记\weapon.h(17) : error C2270: '<' : modifiers not allowed on nonmember functions
e:\msdev98\myprojects\西游记\weapon.h(17) : error C2803: 'operator <' must have at least one formal parameter of class type
e:\msdev98\myprojects\西游记\weapon.h(17) : error C2805: binary 'operator <' has too few parameters
e:\msdev98\myprojects\西游记\weapon.h(18) : error C2143: syntax error : missing ',' before '&'
e:\msdev98\myprojects\西游记\weapon.h(18) : error C2059: syntax error : '&'
e:\msdev98\myprojects\西游记\weapon.h(18) : error C2270: '>' : modifiers not allowed on nonmember functions
e:\msdev98\myprojects\西游记\weapon.h(18) : error C2803: 'operator >' must have at least one formal parameter of class type
e:\msdev98\myprojects\西游记\weapon.h(18) : error C2805: binary 'operator >' has too few parameters
e:\msdev98\myprojects\西游记\weapon.h(19) : warning C4508: 'Weapon' : function should return a value; 'void' return type assumed
e:\msdev98\myprojects\西游记\weapon.h(20) : error C2923: 'vector' : 'Weapon' is invalid as template argument '#1', type expected
e:\msdev98\myprojects\西游记\weapon.h(7) : see declaration of 'Weapon'
e:\msdev98\myprojects\西游记\weapon.h(20) : error C2923: 'priority_queue' : 'Weapon' is invalid as template argument '#1', type expected
e:\msdev98\myprojects\西游记\weapon.h(7) : see declaration of 'Weapon'
e:\msdev98\myprojects\西游记\weapon.h(22) : error C2061: syntax error : identifier 'osteam'
e:\msdev98\myprojects\西游记\weapon.h(22) : error C2809: 'operator <<' has no formal parameters
e:\msdev98\myprojects\西游记\weapon.cpp(6) : error C2061: syntax error : identifier 'Weapon'
e:\msdev98\myprojects\西游记\weapon.cpp(7) : error C2805: binary 'operator <<' has too few parameters
e:\msdev98\myprojects\西游记\weapon.cpp(8) : error C2065: 'weapon' : undeclared identifier
e:\msdev98\myprojects\西游记\weapon.cpp(8) : error C2228: left of '.getName' must have class/struct/union type
e:\msdev98\myprojects\西游记\weapon.cpp(8) : error C2228: left of '.getPower' must have class/struct/union type
e:\msdev98\myprojects\西游记\weapon.cpp(11) : error C2653: 'Weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(12) : error C2084: function 'int __cdecl Weapon(void)' already has a body
e:\msdev98\myprojects\西游记\weapon.cpp(13) : error C2653: 'Weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(13) : error C2373: 'weapon' : redefinition; different type modifiers
e:\msdev98\myprojects\西游记\weapon.cpp(14) : error C2550: 'weapon' : constructor initializer lists are only allowed on constructor definitions
e:\msdev98\myprojects\西游记\weapon.cpp(14) : warning C4508: 'weapon' : function should return a value; 'void' return type assumed
e:\msdev98\myprojects\西游记\weapon.cpp(15) : error C2653: 'weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(16) : error C2065: '_name' : undeclared identifier
e:\msdev98\myprojects\西游记\weapon.cpp(18) : error C2653: 'weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(19) : error C2065: '_power' : undeclared identifier
e:\msdev98\myprojects\西游记\weapon.cpp(21) : error C2653: 'weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(21) : error C2143: syntax error : missing ',' before '&'
e:\msdev98\myprojects\西游记\weapon.cpp(21) : error C2059: syntax error : '&'
e:\msdev98\myprojects\西游记\weapon.cpp(22) : error C2270: '<' : modifiers not allowed on nonmember functions
e:\msdev98\myprojects\西游记\weapon.cpp(23) : error C2673: '<' : global functions do not have 'this' pointers
e:\msdev98\myprojects\西游记\weapon.cpp(23) : error C2227: left of '->_power' must point to class/struct/union
e:\msdev98\myprojects\西游记\weapon.cpp(23) : error C2065: 'other' : undeclared identifier
e:\msdev98\myprojects\西游记\weapon.cpp(23) : error C2228: left of '._power' must have class/struct/union type
e:\msdev98\myprojects\西游记\weapon.cpp(25) : error C2653: 'weapon' : is not a class or namespace name
e:\msdev98\myprojects\西游记\weapon.cpp(25) : error C2143: syntax error : missing ',' before '&'
e:\msdev98\myprojects\西游记\weapon.cpp(25) : error C2059: syntax error : '&'
e:\msdev98\myprojects\西游记\weapon.cpp(26) : error C2270: '>' : modifiers not allowed on nonmember functions
e:\msdev98\myprojects\西游记\weapon.cpp(27) : error C2673: '>' : global functions do not have 'this' pointers
e:\msdev98\myprojects\西游记\weapon.cpp(27) : error C2227: left of '->_power' must point to class/struct/union
e:\msdev98\myprojects\西游记\weapon.cpp(27) : error C2228: left of '._power' must have class/struct/union type

...全文
275 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
scq2099yt 2008-04-18
  • 打赏
  • 举报
回复
up
yupengchen951124 2008-04-18
  • 打赏
  • 举报
回复
怎么把西游记也显示出来了……呵呵
lyfyes 2008-04-18
  • 打赏
  • 举报
回复
你的;用法,有用错地方啊.如果要调试的话,可以将代码发给我,我帮你调116509625@163.com
Eleven 2008-04-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 shelliu 的回复:]
#include <iostream>
#include <string>
#include <queue>
是不是该加个.h啊?
[/Quote]
那是C++的标准库,不加.h
makun 2008-04-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 shelliu 的回复:]
#include <iostream>
#include <string>
#include <queue>
是不是该加个.h啊?
[/Quote]

你等级怎么升上来的?
STL的内容。
shelliu 2008-04-18
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
#include <queue>
是不是该加个.h啊?
ToperRay 2008-04-18
  • 打赏
  • 举报
回复
看仔细了再敲,怀疑你敲错了。
fox000002 2008-04-18
  • 打赏
  • 举报
回复
代码写得规范些。





// weapon.h
#ifndef WEAPON_H_
#define WEAPON_H_

#pragma once

#include <iostream>
#include <string>
#include <queue>
using namespace std;

class Weapon
{
private:
string _name;
int _power;
public:
Weapon();
Weapon(string name,int power);
string GetName();
int GetPower();
bool operator < (const Weapon &other) const;
bool operator > (const Weapon &other) const;
};
typedef priority_queue < Weapon,vector <Weapon> >Weapons;
//对流的操作支持
ostream &operator << (ostream &cout, Weapon &weapon);

#endif // WEAPON_H_

// weapon.cpp
#include "weapon.h"

using namespace std;

//让Weapon支持流的操作
ostream &operator <<(ostream &cout,Weapon &weapon)
{
cout <<weapon.GetName() <<"(" <<weapon.GetPower() <<")";
return cout;
}

Weapon::Weapon()
{ }

Weapon::Weapon(string name,int power):_name(name),_power(power)
{ }
string Weapon::GetName()
{ return _name; }

int Weapon::GetPower()
{ return _power; }

bool Weapon::operator <(const Weapon &other) const
{
return this->_power < other._power;
}
bool Weapon::operator >(const Weapon &other) const
{
return this->_power > other._power;
}


yaoy053619 2008-04-18
  • 打赏
  • 举报
回复
class Weapon() 不写括号。class Weapon
流运算符<<间不用加空格
yaoy053619 2008-04-18
  • 打赏
  • 举报
回复
class Weapon()应该写成class Weapon,不用加括号。
ostream &operator < <(osteam &cout,Weapon &weapon);
去掉<<中间的空格。
其他的错误较简单。
我编译过你的程序了,按照上述办法可以编通。
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧