Lecture 3 - A Closer Look at Classes
Lecture 3 - A Closer Look at Classes
Lecture Three
Assigning Objects
One object can be assigned to another provided that both objects are
of the same type.
When one object is assigned to another, a bitwise copy of all the data
members is made.
1
8/17/2014
Assigning Objects
#include <iostream> char stack::pop(){
using namespace std; if (tos == 0){
cout << “Stack is empty\n”;
#define SIZE 10 return;
}
class stack { return stck[--tos];
char stck[SIZE]; }
int tos;
public: int main(){
stack() {tos = 0}; stack s1, s2;
void push(char ch);
char pop(); s1.push(‘a’);
}; s1.push(‘b’);
2
8/17/2014
3
8/17/2014
OUTPUT:
copy: value of i: 100
main: value of i: 100
4
8/17/2014
Friend Function
Friend Function
5
8/17/2014
Friend Function