Okay so I\'m a bit of a noob at C++ and in my second assignment I am required to make classes with public and private arguments etc, etc. Basically the mutator functions won\'t
You should use std::
in the class declaration. See Why is “using namespace std;” considered bad practice? on the question why.
Your set_
methods take unsigned
arguments. You cannot assign an unsigned to a string like PhoneNumber_ = x;
. The arguments need to be strings.
You'd need to change your members like
std::string get_PhoneNumber() const { return PhoneNumber_; } // Accessor
const void set_PhoneNumber(std::string const & x) { PhoneNumber_ = x; } // Mutator
When you write temp->get_PhoneNumber() = id;
your intention is clearly to set the value for PhoneNumber_
, so why do you use the get_ method? Just use the appropriate set_ method and write temp->set_PhoneNumber(id);
.
Generally avoid pointers in C++. If you're really in need of a pointer use a smart pointer like std::unique_ptr
or std::shared_ptr
(if and only if you are required to use a plain pointer: use one).
A 'blank' default value for a std::string
is an empty string like
std::string const & id = std::string{}
Appears clearer to me.
To create an object of type Customer
with blank/empty member strings you do not need to do more than Customer customer_object;
since there is an implicitly declared default constructor which uses the std::string
default constructor which results in an empty strign anyway.
Usually a constructor is used to create an object depending on some arguments values.
You could easily write one that takes all required values and can be used as a default constructo anyway by adding something along the lines of
Customer(const std::string& id = std::string{},
const std::string& name = std::string{},
const std::string& address = std::string{})
: PhoneNumber_(id), Name_(name), Address_(address)
{ }
to your class. See another C++ Class Initialization List example.
See another C++ Class Initialization List example.