So I need to program a code which will display the values of all my objects which currently are "Monday and Tuesday." I am getting two errors under my printDay function.
Error c2275 'DayOFTheWeek': illegal use of this type as an expression
Error c2228: left of '.printDay' must have class/struct/union

I will admit I know I'm not properly programming this part correctly but I have already failed other attempts to fix this.

/*Author:DaniwebOS*/
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

class DayOfTheWeek
{
private:
	string day;
public:
	void setDay(string);
	void printDay() const;
	string getDay() const;
};

void DayOfTheWeek::printDay() const
{
	cout << "The value of the" << DayOfTheWeek.getDay << "is " << day << "." << endl;
}

string DayOfTheWeek::getDay() const
{
	return day;
}

int main()
{
	DayOfTheWeek Monday;
	DayOfTheWeek Tuesday;
	Monday.setDay("Mon");
	Tuesday.setDay("Tues");
	string currentDay = Monday.getDay();
	currentDay = Tuesday.getDay();
	Monday.printDay();
	Tuesday.printDay();	
	getch();
	return 0;
}

What are you trying to print out with "DayOfTheWeek.getDay"? That call would only work if getDay were a static member variable of DayOfTheWeek.

Which line is the compiler referring to with the second error message?

Line 18, basically what I want it to due is to cout the days and its values which would be "Mon/Tues"

So why do you need that DayOfTheWeek.getDay portion at all then? (it's not doing anything anyway) Just output the day with that cout.

Well I figured that was an error, I just can't figure out how to get line 18 to work properly like it to display

The value of the Monday object is Mons.
The Value of the Tuesday object is Tues.

There's no readily available way to get the name of an object from within the program, unfortunately.

So what would be the best way to display the object's name and its value?

Just display the value, I don't think that anyone is expecting you to display the object's name (I suppose you could make a map, as someone will probably suggest, but that may be beyond what your instructor is expecting you to know at this point).

Why do you have to create a class for this? Just make a string variable.

Rather than DayOfTheWeek.getDay, use getDay()

Since you are calling a method of the class from withing the class

use getDay()

He's already accomplishing that with the "day" that's in the cout statement. He's trying to print the name of the object with the DayOfTheWeek.getDay, which isn't giving him what he needs, so I was saying he should just eliminate the first part outright.

Perhaps name the object?

class DayOfTheWeek
{
public:
    DayOfTheWeek(const std::string &name_)
    :_name(name_)
    {;}
    const std::string &getName() {return _name;}
private:
    std::string _name;
};

int main()
{
    DayOfTheWeek s("monday");;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.