Topcoder Problem の C++ で書かれたソリューションを提出しようとしています。
コードはローカル マシンで実行されています (Ubuntu 12.04 Linux、gcc)
しかし、コンパイル中に次のエラーが発生します (Topcoder Compiler)。
コンパイル エラー:
In file included from top level:11:
Your class or method was improperly declared: In function ‘std::string _wrapper::thunk(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::string)’:
Your class or method was improperly declared:20003: error: invalid use of incomplete type ‘struct UserName’
end of your submission:10030: error: forward declaration of ‘struct UserName’
以下は私のコードです:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
class Username {
public:
string newMember(vector <string> existingNames, string newName) {
int i, j, result = 0;
for(i=0;i<existingNames.size();i++) {
if(newName == existingNames[i]) {
result = 1;
}
}
if(result == 1) {
for(i=1;i<50;i++) {
result = 0;
string newUsername = newName;
stringstream k;
k << i;
newUsername += k.str();
for(j=0; j<existingNames.size(); j++) {
if(newUsername == existingNames[j]) {
result = 1;
}
}
if (result == 0) {
return(newUsername);
}
}
} else {
return(newName);
}
}
};
誰かが私が実際に間違っているところを教えてもらえますか?