I'm getting the following error when I try to compile my code. I've read through other questions from people who get the same error but none of the answers are relevant to me.
user.cpp:15:7: error: expected unqualified-id before ‘int’
User(int user_id, string user_name, int user_year, int user_zip)
^
user.cpp:15:7: error: expected ‘)’ before ‘int’
Any help would be appreciated.
user.cpp:
#include "user.h"
using namespace std;
User(int user_id, string user_name, int user_year, int user_zip)
{
id = user_id;
name = user_name;
year = user_year;
zip = user_zip;
friends = {};
}
~User()
{
}
void User::add_friend(int id)
{
friends.push_back(id);
}
void User::delete_friend(int id)
{
for (int i = 0; i < friends.size();++i)
{
if (friends[i] == id)
{
friends.erase(vec.begin() + i);
}
}
}
int User::getID()
{
return id;
}
string User::getName()
{
return name;
}
int User::getYear()
{
return year;
}
int User::getZip()
{
return zip;
}
vector<int>* User::getFriends()
{
return &friends;
}
user.h:
#ifndef USER_H
#define USER_H
#include <string>
#include <vector>
class User {
public:
User(int user_id, std::string user_name, int user_year, int user_zip);
~User();
void add_friend(int id);
void delete_friend(int id);
int getID();
std::string getName();
int getYear();
int getZip();
std::vector<int>* getFriends();
private:
int id;
std::string name;
int year;
int zip;
std::vector<int> friends;
};
#endif
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…