Code:
#include <string>
#include <iostream>
using namespace std;
class Color
{
public:
// const is used becouse this function
// does not change anything. It just returns color.
string getColor() const;
// void? Function just sets the color.
// Does not return anything.
void setColor(string new_color);
private:
string color;
};
string Color::getColor() const
{
// return member of the Color class, 'color'
return Color::color;
}
void Color::setColor(string new_color)
{
Color::color = new_color;
}
int main()
{
Color myColorer; // make instance of the Color class
cout<<"The color now, is currently "<<myColorer.getColor()<<" .";
cout<<"\n\nWe will now set the color to black.";
myColorer.setColor("black");
cout << "\nNow the color is " << myColorer.getColor();
getchar(); // wait for keypress
}
[NOTE] :
Some things won't work if you have older compiler.