Hey guys, quick question, I am trying to overload the = operator as in operator=() but I am getting errors when I try to do it globally. Doing it privately yields no errors at all.
For simplicity i have included only the header file but the definitions can be supplied if needed.
This method works just fine.
THis method yields the following errors:
For simplicity i have included only the header file but the definitions can be supplied if needed.
Rich (BB code):
#ifndef PRACTICE_H
#define PRACTICE_H
#include <iostream>
#include <string>
using namespace std;
class practice
{
public:
practice(const char[] = "empty");
practice (const practice &);
~practice();
char* reader();
void input(const char*);
void input(const string &);
bool operator==(const practice &);
bool operator!=(const practice &);
practice & operator=(const practice &);
friend practice & operator+(practice &, const practice &);
friend istream & operator>>(istream &, practice &);
friend ostream & operator<<(ostream &, const practice &);
private:
char *ptr;
};
#endif
Rich (BB code):
#ifndef PRACTICE_H
#define PRACTICE_H
#include <iostream>
#include <string>
using namespace std;
class practice
{
public:
practice(const char[] = "empty");
practice (const practice &);
~practice();
char* reader();
void input(const char*);
void input(const string &);
bool operator==(const practice &);
bool operator!=(const practice &);
friend practice & operator=(practice &, const practice &);
friend practice & operator+(practice &, const practice &);
friend istream & operator>>(istream &, practice &);
friend ostream & operator<<(ostream &, const practice &);
private:
char *ptr;
};
#endif
1>------ Build started: Project: Exam practice, Configuration: Debug Win32 ------
1>Compiling...
1>Practice implementation.cpp
1>z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(22) : error C2801: 'operator =' must be a non-static member
1>z:\college\year2\semester 2\programming\exam practice\exam practice\practice implementation.cpp(58) : error C2801: 'operator =' must be a non-static member
1>z:\college\year2\semester 2\programming\exam practice\exam practice\practice implementation.cpp(59) : error C2248: 'practice:tr' : cannot access private member declared in class 'practice'
1> z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(28) : see declaration of 'practice:tr'
1> z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(9) : see declaration of 'practice'
1>z:\college\year2\semester 2\programming\exam practice\exam practice\practice implementation.cpp(59) : error C2248: 'practice:tr' : cannot access private member declared in class 'practice'
1> z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(28) : see declaration of 'practice:tr'
1> z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(9) : see declaration of 'practice'
1>Test file.cpp
1>z:\college\year2\semester 2\programming\exam practice\exam practice\practice.h(22) : error C2801: 'operator =' must be a non-static member
1>Generating Code...
1>Build log was saved at "file://z:\College\Year2\Semester 2\Programming\Exam practice\Exam practice\Debug\BuildLog.htm"
1>Exam practice - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited: