What is wrong in these classes?
Please help me finding the error. Its driving me crazy! It gives an error in account.cpp at setName
it underlines (name) in
depo.setName(name);
Name.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
/* Name Class Specification */
#ifndef NAME_H
#define NAME_H
#include <string>
using namespace std;
//Name class declarations
class Name {
string last;
string first;
public:
// mutators (or setter member functions)
void setLastname(string);
void setFirstname(string);
// accessors (or getter member functions)
string getLastname() const;
string getFirstname() const;
};
#endif
|
Name.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
/* Name Class Implementation */
#include <string>
#include "Name.h"
using namespace std;
void Name::setLastname(string lastname)
{
last = lastname;
return;
}
void Name::setFirstname(string firstname)
{
first = firstname;
return;
}
string Name::getLastname() const
{
return (last);
}
string Name::getFirstname() const
{
return (first);
}
|
Depositor.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef DEPOSITOR_H
#define DEPOSITOR_H
#include<string>
#include"Name.h"
using namespace std;
class Depositor{
Name name;
char SSN;
public:
void setName(string lastname, string firstname);
void setSSN(char SSN);
Name getName() const;
char getSSN() const;
};
#endif
|
Depositor.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <string>
#include "Depositor.h"
using namespace std;
void Depositor::setName(string lastname, string firstname)
{
name.setLastname(lastname);
name.setFirstname(firstname);
return;
}
void Depositor::setSSN(char ssn)
{
SSN = ssn;
return;
}
Name Depositor::getName() const
{
return (name);
}
char Depositor::getSSN() const
{
return(SSN);
}
|
Account.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include"Depositor.h"
using namespace std;
class Account{
Depositor depo;
char acc_num;
double acc_bal;
char acc_type;
public:
// mutators (or setter member functions)
void setdepositor(Name name, char SSN);
void setacc_num(char);
void setacc_bal(double);
void setacc_type(char);
// accessors (or getter member functions)
Depositor getdepositor() const;
char getacc_num() const;
double getacc_bal() const;
char getacc_type() const;
};
#endif
|
Account.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include "Account.h"
#include<string>
using namespace std;
void Account::setdepositor(Name name, char ssn)
{
depo.setName(name);
depo.setSSN(ssn);
return;
}
void Account::setacc_num(char Acc_Num)
{
acc_num = Acc_Num;
return;
}
void Account::setacc_bal(double Acc_Bal)
{
acc_bal = Acc_Bal;
}
void Account::setacc_type(char Acc_Type)
{
acc_type = Acc_Type;
}
Depositor Account::getdepositor() const
{
return (depo);
}
char Account::getacc_num() const
{
return (acc_num);
}
double Account::getacc_bal() const
{
return (acc_bal);
}
char Account::getacc_type() const
{
return (acc_type);
}
|
Last edited on
Mismatch↓↓↓
1 2 3
|
void Depositor::setName(string lastname, string firstname)
//
depo.setName(name);
|
What is the error compiler gives you?
it says Error: no suitable user-defined conversion from "Name" to "std::string" exists
Well, it is just like that: function expects two strings, you gave it on Name variable.
Topic archived. No new replies allowed.