2012-07-02 42 views
1

我有以下的C++(這並沒有真正做任何事情...)後跟虛假是非法的?

#include "stdafx.h" 
#include <iostream> 

using namespace std; 

class Ranker 
{ 
    int up, down; 
    public: 
    void set_ranks(int, int); 
    int rank(int, int, int, double); 
} 

void Ranker::set_ranks(int a, int b) 
{ 
    up = a; 
    down = b; 
} 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    return 0; 
} 

當我運行它,它帶來了在段V C++

1>------ Build started: Project: rankclass, Configuration: Debug Win32 ------ 
1> rankclass.cpp 
1>c:\users\student\desktop\solomon w. c++\rankclass\rankclass\rankclass.cpp(17): error C2628: 'Ranker' followed by 'void' is illegal (did you forget a ';'?) 
1>c:\users\student\desktop\solomon w. c++\rankclass\rankclass\rankclass.cpp(18): error C2556: 'Ranker Ranker::set_ranks(int,int)' : overloaded function differs only by return type from 'void Ranker::set_ranks(int,int)' 
1>   c:\users\student\desktop\solomon w. c++\rankclass\rankclass\rankclass.cpp(13) : see declaration of 'Ranker::set_ranks' 
1>c:\users\student\desktop\solomon w. c++\rankclass\rankclass\rankclass.cpp(18): error C2371: 'Ranker::set_ranks' : redefinition; different basic types 
1>   c:\users\student\desktop\solomon w. c++\rankclass\rankclass\rankclass.cpp(13) : see declaration of 'Ranker::set_ranks' 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

以下錯誤消息爲什麼這個...... Ranker沒有跟着void?!?!

+3

錯誤C2628:「排行器」,然後「無效」是非法的(你忘了一';'?) – RobB

+0

^^^也許在第12行;-) – AJG85

+2

爲什麼2張選票?這看起來是錯誤的*不讀錯誤信息*將成爲聲譽的來源...... –

回答

19

您在Ranker聲明後缺少分號。

它應該是:

class Ranker 
{ 
    int up, down; 
    public: 
    void set_ranks(int, int); 
    int rank(int, int, int, double); 
}; // <--- Note semicolon 
4

類定義一個分號,加一個第12行