我保持一个错误基本上说所有的memberstype函数已经在persontype类中声明创建我想知道如何修复此错误第一条错误消息说,membershiptime :: membership类型也在人类型对象中定义它是不,并且第二个错误消息说第二个construcor也已经在persontype中定义我该如何修复这个错误?
#include <iostream>
#include <string>
using namespace std;
class addressType { //class defintions and prototypes member variables
public:
addressType();
string streetAddressNum, streetName, streetType, city, stateInitials;
int zipCode;
};
class personType
{
public:
personType();
string firstName;
string lastName;
int personNum;
char gender;
int personID;
addressType address;
void setInterest1(string interest1);//mutator
void setInterest2(string interest2);
void printPerson();
string GetInterest1() const; // Accessor
string GetInterest2() const;
private:
string SetInterest1;
string SetInterest2;
};
//define membershipType class
class membershipType :public personType
{
public:
char membership_type;
char membership_status;
membershipType(); // 1st constructor
membershipType(char, char); // 2nd constructor
void print_member_type();
};
membershipType::membershipType()
{
membership_type = ' ';
membership_status = ' ';
}
membershipType::membershipType(char members1, char members2)
{
members1 = membership_type;
members2 = membership_status;;
}
void membershipType::print_member_type()
{
cout << firstName << " " << lastName << " " << gender << " " <<
personID << " " << address.streetAddressNum << " "
<< address.streetName << " " << address.streetType
<< " " << address.city << " " << address.stateInitials
<< " " << address.zipCode << " " <<membership_status<<membership_type<<endl;
}
#include "personType.h"
personType::personType()
{//constructor
int personNum = 0;
int personID = 0;
}
addressType::addressType() {
int zipCode = 0;
}
void personType::setInterest1(string interest1) {
SetInterest1 = interest1;
}//mutator
void personType::setInterest2(string interest2) {
SetInterest2 = interest2;
}
string personType:: GetInterest1() const
{
return SetInterest1;
}// Accessor
string personType:: GetInterest2() const {
return SetInterest2;
}
void personType :: printPerson() {//constructor
cout << firstName << " " << lastName << " " << gender << " " <<
personID << " " << address.streetAddressNum << " "
<< address.streetName << " " << address.streetType
<< " " << address.city << " " << address.stateInitials
<< " " << address.zipCode << " " << SetInterest1 << " " << SetInterest2 << endl;
}
答案 0 :(得分:0)
您需要单独组织课程:
//main.cpp
#include <iostream>
#include <string>
using namespace std;
#include "membershipType.h"
membershipType::membershipType()
{
membership_type = ' ';
membership_status = ' ';
}
membershipType::membershipType(char members1, char members2)
{
members1 = membership_type;
members2 = membership_status;;
}
void membershipType::print_member_type()
{
cout << firstName << " " << lastName << " " << gender << " " <<
personID << " " << address.streetAddressNum << " "
<< address.streetName << " " << address.streetType
<< " " << address.city << " " << address.stateInitials
<< " " << address.zipCode << " " << membership_status << membership_type << endl;
}
personType::personType()
{//constructor
int personNum = 0;
int personID = 0;
}
addressType::addressType() {
int zipCode = 0;
}
void personType::setInterest1(string interest1) {
SetInterest1 = interest1;
}//mutator
void personType::setInterest2(string interest2) {
SetInterest2 = interest2;
}
string personType::GetInterest1() const
{
return SetInterest1;
}// Accessor
string personType::GetInterest2() const {
return SetInterest2;
}
void personType::printPerson() {//constructor
cout << firstName << " " << lastName << " " << gender << " " <<
personID << " " << address.streetAddressNum << " "
<< address.streetName << " " << address.streetType
<< " " << address.city << " " << address.stateInitials
<< " " << address.zipCode << " " << SetInterest1 << " " << SetInterest2 << endl;
}
int main() {
personType* p = new personType;
p->printPerson();
}
personType.h:
#include "addressType.h"
class personType
{
public:
personType();
std::string firstName;
std::string lastName;
int personNum;
char gender;
int personID;
addressType address;
void setInterest1(std::string interest1);//mutator
void setInterest2(std::string interest2);
void printPerson();
std::string GetInterest1() const; // Accessor
std::string GetInterest2() const;
private:
std::string SetInterest1;
std::string SetInterest2;
};
你是addressType.h
class addressType { //class defintions and prototypes member variables
public:
addressType();
std::string streetAddressNum, streetName, streetType, city, stateInitials;
int zipCode;
};
您的membershipType.h
//define membershipType class
class membershipType :public personType
{
public:
char membership_type;
char membership_status;
membershipType(); // 1st constructor
membershipType(char, char); // 2nd constructor
void print_member_type();
};
1&gt; ------Débutdelagénération:Projet:ConsoleApplication2,配置:发布Win32 ------ 1 GT; main.cpp中 1 GT; Générationdecode en cours 1 GT;编译了所有52个函数,因为找不到以前编译的可用IPDB / IOBJ。 1 GT; Fin delagénérationducode 1 GT; ConsoleApplication2.vcxproj - &gt; C:\出\ frosbite_sdk_typeinfo \ SDK \ ConsoleApplication2 \发布\ ConsoleApplication2.exe ==========Génération:1aréussi,0aéchoué,0misàjour,0aétéignoré==========