naseeam
asked on
What does class variable assignment mean ?
int x = 4;
int y = 7:
y = x; // now y contains 4
This isn't true for class variable assignments. In class variable assignments, members of one class aren't assigned to members of another class. Then, what does it mean to assign one class variable to another ?
#include <iostream>
#include <string>
class GradeBook
{
public:
GradeBook( std::string );
GradeBook() {};
void setCourseName( std::string );
std::string getCourseName();
void displayMessage();
std::string courseName;
};
Program output is: Course Name: CS101
What does the following assignment statement mean ?
another = gradebook1;
int y = 7:
y = x; // now y contains 4
This isn't true for class variable assignments. In class variable assignments, members of one class aren't assigned to members of another class. Then, what does it mean to assign one class variable to another ?
#include <iostream>
#include <string>
class GradeBook
{
public:
GradeBook( std::string );
GradeBook() {};
void setCourseName( std::string );
std::string getCourseName();
void displayMessage();
std::string courseName;
};
#include <iostream>
#include <string>
class GradeBook
{
public:
GradeBook( std::string );
GradeBook() {};
void setCourseName( std::string );
std::string getCourseName();
void displayMessage();
std::string courseName;
};
int main()
{
GradeBook gradebook1, another;
gradebook1.courseName = "CS101";
another.courseName = "CS200";
another = gradebook1;
std::cout << "\n" << "Course Name is: " << another.courseName << "\n";
return 0;
}
Program output is: Course Name: CS101
What does the following assignment statement mean ?
another = gradebook1;
ASKER
another = gradebook1;
I think this assignment statment shouldn't be allowed. Now we have lost one instance of class. We cannot get access to it's members.
I think this assignment statment shouldn't be allowed. Now we have lost one instance of class. We cannot get access to it's members.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER