Operator overloading error when called "name not allowed in member function"

I created an overloaded but i am getting weird errors when i call it. I am very new to pointers so I have no clue where to look.

Artist.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
  #pragma once
#include <string>
#include <iostream>

using namespace std;
//Artist Class Definition.
class Artist
{
public:
	//Defualt Constructer 
	Artist::Artist();
	// Getter Function.
	string getName();
	string getCountry();
	// Set Function
	void setName(string);
	void setCountry(string);
	~Artist();
	Artist&Artist::operator=(const Artist& p);

private:
	string *firstName;
	string country;
};


Artist.cpp

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
36
37
38
39
#include <string>
#include <iostream>
#include <fstream>
#include "artist.h"

using namespace std;

//Default Constructer
Artist::Artist() {
	//Now a pointer.
	*firstName = "";
	country = "";
}

Artist& Artist::operator=(const Artist& p) {
		firstName = p.firstName;  
		return *this;
	
}//end operator=

//Deconstructer
Artist::~Artist() {
	delete firstName;
}
//Set & Get Functions
void Artist::setName(string f) {
	*firstName = f;
}

void Artist::setCountry(string c) {
	country = c;
}

string Artist::getName() {
	return *firstName;
}
string Artist::getCountry() {
	return country;
}


main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


#include <string>
#include <iostream>
#include <fstream>
#include "song.h"
#include "album.h"

int main() {
	//Variables.
	string option;
	string file_name;
	Album myalbum;
	bool active = true;

	Artist theArt;
	theArt.operator=;
}





Severity Code Description Project File Line Suppression State
Error C4596 '{ctor}': illegal qualified name in member declaration Project1 c:\users\ultimax\desktop\hw 4 ali\staticlib1\staticlib1\artist.h 11
Error (active) E0427 qualified name is not allowed in member declaration Project1 c:\Users\Ultimax\Desktop\hw 4 ali\staticlib1\staticlib1\artist.h 11
Error (active) E0427 qualified name is not allowed in member declaration Project1 c:\Users\Ultimax\Desktop\hw 4 ali\staticlib1\staticlib1\artist.h 19
Error C4596 '=': illegal qualified name in member declaration Project1 c:\users\ultimax\desktop\hw 4 ali\staticlib1\staticlib1\artist.h 19
Error C3867 'Artist::=': non-standard syntax; use '&' to create a pointer to member Project1 c:\users\ultimax\source\repos\project1\project1\source.cpp 25
Last edited on
Why are you using a pointer at all here?

In the class declaration, don't put Artist:: before function names.

Nothing to do with pointers. You just wrote the class declaration wrongly.

using namespace std; Do not ever put this in your header files. Ever.
Last edited on
Thanks.But i just decided to get rid of it. I am using a pointer because my assignment is to add pointers to my static library I made. It's tougher then i thought it would be :/.
Last edited on
Topic archived. No new replies allowed.