error C2143 and error C2059

hqliu41 2011-10-28 03:18:05
运行C++程序的时候,老是提示错误红色部分处,6 errors)

1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(189) : error C2143: syntax error : missing ')' before 'constant'
1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(189) : error C2059: syntax error : ')'
1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(190) : error C2143: syntax error : missing ')' before 'constant'
1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(190) : error C2059: syntax error : ')'
1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(191) : error C2143: syntax error : missing ')' before 'constant'
1>f:\c workspace\111026_template_dsaa_p33\111026_template_dsaa_p33\template_dsaa.cpp(191) : error C2059: syntax error : ')'

想问一下到底是什么原因呢? 怎么样修改这个程序才能运行成功呢?



源代码:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

template <typename Comparable>
const Comparable & findMax( const vector<Comparable> & a )
{
int maxIndex = 0;

for ( int i = 1; i < a.size(); i++ )
if ( a[ maxIndex ] < a[ i ] )
maxIndex = i;

return a[ maxIndex ];
}

class Employee
{
public:
void setValue( const string & n, double s )
{
name = n;
salary = s;
}

const string & getName() const
{
return name;
}

void print( ostream & out ) const
{
out << name << "( " << salary << " ) ";
}

bool operator< ( const Employee & rhs ) const
{
return salary < rhs.salary ;
}

//other general accessors and mutators, not shown
private:
string name;
double salary;
};

//define an output operator for Employee
ostream & operator<< ( ostream & out, const Employee & rhs )
{
rhs.print( out );
return out;
}

int main()
{
vector<Employee> v( 3 );

[b] v[0].setValue( "Gegore Bush", 400 000.00 );
v[1].setValue( "Bill Gates", 2 000 000 000.00 );
v[2].setValue( "Dr. Phil", 13 000 000.00 );[/
b]

cout << findMax( v ) << endl;

return 0;
}
...全文
145 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqliu41 2011-10-30
  • 打赏
  • 举报
回复
谢谢楼上了!

[Quote=引用 2 楼 xingfeng2510 的回复:]
楼上正解,去掉数字之间的空格就行了
v[0].setValue( "Gegore Bush", 400000.00 );
v[1].setValue( "Bill Gates", 2000000000.00 );
v[2].setValue( "Dr. Phil", 13000000.00 );
[/Quote]
xingfeng2510 2011-10-28
  • 打赏
  • 举报
回复
楼上正解,去掉数字之间的空格就行了
v[0].setValue( "Gegore Bush", 400000.00 );
v[1].setValue( "Bill Gates", 2000000000.00 );
v[2].setValue( "Dr. Phil", 13000000.00 );
qq120848369 2011-10-28
  • 打赏
  • 举报
回复
v[0].setValue( "Gegore Bush", 400 000.00 );
v[1].setValue( "Bill Gates", 2 000 000 000.00 );
v[2].setValue( "Dr. Phil", 13 000 000.00 );


数字中间那些空格是毛?

64,674

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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