error C2143 and error C2059
运行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;
}