Help error C2659

I am brand new to posting for help on a forum as well as C++. So, if posted to much code, let me know and I will fix it in the future. I am trying to do a lab in a class in which I have to create 3 classes (each with a .h and .cpp file) as well as a main .cpp file to print out some info. However, when I run the program I am getting a C2659 error which is "function left as an operand" for each of my Setter statements in the class file. Please help. I have already spent way too much time banging my head against the wall on this lab assignment. Thanks!


#include "ATeacher.h"
#include "pch.h"
#include <iostream>

ATeacher::ATeacher()
{
}

ATeacher::ATeacher(std::string fName, std::string lName)
{
std::string firstName = fName;
std::string lastName = lName;

}

ATeacher::ATeacher(std::string fName, std::string lName, int age, std::string address, std::string city, int phone)
{
std::string firstName = fName;
std::string lastName = lName;
int aAge = age;
std::string aAddress = address;
std::string aCity = city;
int phoneNumber = phone;
}

ATeacher::~ATeacher()
{
}

void ATeacher::SetFirstName(std::string fName)
{
this->firstName = fName;
}

std::string ATeacher::GetFirstName()
{
return this ->firstName; <error C2659: '=': function as left operand>
}

void ATeacher::SetLastName(std::string lName)
{
this->lastName = lName; <error C2659: '=': function as left operand>
}

std::string ATeacher::GetLastName()
{
return this ->lastName;
}

void ATeacher::SetAge(int age)
{
if (age>0)
{
this->aAge = age;
}
else
{
std::cout << "Enter a valid age.";
}
}

int ATeacher::GetAge()
{
return this ->aAge;
}

void ATeacher::SetAddress(std::string address)
{
this->aAddress = address; <error C2659: '=': function as left operand>
}

std::string ATeacher::GetAddress()
{
return this ->aAddress;
}

void ATeacher::SetCity(std::string city)
{
this->aCity = city;
}

std::string ATeacher::GetCity()
{
return this ->aCity;
}

void ATeacher::SetPhoneNumber(int phone)
{
this->phoneNumber = phone;
}

int ATeacher::GetPhoneNumber()
{
return this->phoneNumber;
}



void ATeacher::GradeStudent()
{
std::cout << "Student graded.";
}

void ATeacher::SitInClass()
{
std::cout << "Sitting at the front of the class.";
}
Last edited on
closed account (SECMoG1T)
can you post the exact error and where it occurs, the code you have posted doesn't seem to have any error.

please use code tags when you post your spinets.

the formatting icon similar to <> on the right side
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
I added the error messages in there. Thank you for the help.
closed account (SECMoG1T)
please post the code in Ateacher.h so we can look at it.
Here it is:

#pragma once
#include <string>

class ATeacher
{
private:
std::string firstName();
std::string lastName();

int aAge;

std::string aAddress();
std::string aCity();

int phoneNumber;

public:
int count;
ATeacher();
ATeacher(std::string fName, std::string lName);
ATeacher(std::string fName, std::string lName, int age, std::string address, std::string city, int phone);
~ATeacher();

void SetFirstName(std::string fName);
std::string GetFirstName();

void SetLastName(std::string lName);
std::string GetLastName();

void SetAge(int age);
int GetAge();

void SetAddress(std::string address);
std::string GetAddress();

void SetCity(std::string city);
std::string GetCity();

void SetPhoneNumber(int phone);
int GetPhoneNumber();

void GradeStudent();

void SitInClass();




};
closed account (SECMoG1T)
here are your errors

1
2
3
4
5
6
7
8
9
10
11
12
class ATeacher
{
private:
std::string firstName();///this are suppossed to be member variables not function declarations.
std::string lastName();

int aAge;

std::string aAddress();
std::string aCity();

int phoneNumber;


i think this is what you meant.

1
2
3
4
5
6
7
8
9
10
11
12
class ATeacher
{
private:
std::string firstName;
std::string lastName;

int aAge;

std::string aAddress;
std::string aCity;

int phoneNumber;
Oh my gosh...Thank You!!

I have been taking online courses and am now on the intermediate course.

I have been at this all of 6 weeks, so I believe I am definitely a rank newbie.

closed account (SECMoG1T)
I have been taking online courses all the best.
Topic archived. No new replies allowed.