a nonstatic member reference must be relative to a specific object

I'm attempting to check if one of my bool functions return true or not and it would return that to my overloaded << operator..however im getting an error when i try to do if(isClear())


my header file:
ErrorMessage.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 SICT_ERRORMESSAGE_H__
#define SICT_ERRORMESSAGE_H__
#include <iostream>
namespace sict{
	class ErrorMessage{
		char * message_;
	public:
		ErrorMessage();
		ErrorMessage(const char* errorMessage);
		ErrorMessage(const ErrorMessage& em) = delete;
		ErrorMessage& operator=(const char* errorMessage);
		ErrorMessage& operator=(const ErrorMessage& em) = delete;
		virtual ~ErrorMessage();
		void clear();
		bool isClear()const;
		void message(const char* value);
		const char* message()const;
		
	};
	 std::ostream& operator<<(std::ostream& os, const ErrorMessage& M);
}
#endif




Here is a part of my .cpp file that is relevant to my problem..

1
2
3
4
5
6
7
8
9
10
11
12
13
const char* ErrorMessage::message()const{  // returns the error message
		return message_;
	}

bool ErrorMessage::isClear()const{  // returns true if the message is empty ( NO Error)
		return message_ == 0;
	}

std::ostream& operator<<(std::ostream& os, const ErrorMessage& M){   // prints the ErrorMessage object using ostream
		if (ErrorMessage::isClear()){
			return os << M.message();
		}
	}


How do i reference/call isClear() appropriately?
Last edited on
ErrorMessage::isClear() calls a static method that does not exist.
You need to call to method on an object. M.isClear();
Im.. such an idiot. Thank you.
Hi,

If you are going to have a polymorphic class, you probably need to do the rule of five (six?, counting the dtor) and default all of the special member functions, have a look at the example at the end.

http://en.cppreference.com/w/cpp/language/rule_of_three


Also, you have a virtual dtor, but no other virtual functions; no pure virtual. Presumably a derived class will have some of those? Or this class might not need to be polymorphic?

Is there a reason why you use char * rather than std::string? You probably have a good reason, I am just curious :+)
Topic archived. No new replies allowed.