question about class and mutators

Are you able to write a function that calls all mutators in a class. so say I write a function called input that passes a number in. then inside the function it has all the mutator functions. eg. setMean(double num); can I write something to do this? I haven't finish writing my code for the project so I haven't tried to compile it.
You could but it'd just be the overloaded ctor in disguise:
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
#include <iostream>
#include <string>

class Person
{
    private:
    std::string m_name;
    unsigned int m_age;

    public:

    Person(){}
  //  Person (const std::string& name, const unsigned int& age)
   // : m_name (name), m_age (age) {}

    void setName (const std::string& name) {m_name = name;}
    void setAge (const unsigned int& age) {m_age = age;}
    void allSet (const std::string& name, const unsigned int& age)
    {
        setName(name);setAge(age);
    }
    friend std::ostream& operator << (std::ostream& os, const Person& p);
};
std::ostream& operator << (std::ostream& os, const Person& p)
{
    os << p.m_name << ": " << p.m_age << '\n';
    return os;
}

int main()
{
    Person p;
    p.allSet(std::string("John Smith"), 42);
    std::cout << p ;
}

Topic archived. No new replies allowed.