Reputation: 1148
#ifndef RESERVATIONS_H_INCLUDED
#define RESERVATIONS_H_INCLUDED
#include <vector>
#include <string.c>
class Reservations
{
public:
Reservations::Reservations { }
Reservations(string FullName, int PhoneNum);
string getname() { return FullName; }
int getnumber() { return PhoneNum; }
private:
string FullName;
int PhoneNum;
}
#endif // RESERVATIONS_H_INCLUDED
Reservations::Reservations(string FullName, int PhoneNum) //error on this line
{
FullName = FullName;
PhoneNum = PhoneNum;
}
I get the error in the title, I don't know why it's assuming I want it to have a member of it's own class...
Upvotes: 0
Views: 572
Reputation: 45410
you included wrong header file
Change
#include <string.c>
to
#include <string>
Also use string with full namespace std.
below code should compile with minor fix:
class Reservations
{
public:
Reservations() : PhoneNum(0) {}
Reservations(std::string FullName, int PhoneNum);
std::string getname() { return FullName; }
int getnumber() { return PhoneNum; }
private:
std::string FullName;
int PhoneNum;
};
Reservations::Reservations(std::string FullName, int PhoneNum)
{
this->FullName = FullName;
this->PhoneNum = PhoneNum;
}
// Better use member initializers list
Reservations::Reservations(std::string FullName, int PhoneNum)
: FullName(FullName),
PhoneNum(PhoneNum)
{
}
Upvotes: 2
Reputation: 18803
Do this:
class Reservations
{
public:
//Reservations::Reservations { }
Reservations() { }
....
Upvotes: 0
Reputation: 30273
Do you mean
Reservations::Reservations() { }
instead of
Reservations::Reservations { }
?
Upvotes: 0