Esempio n. 1
0
int main()
{
   Count counter; // create Count object

   cout << "counter.x after instantiation: ";
   counter.print();

   setX( counter, 8 ); // set x using a friend function
   cout << "counter.x after call to setX friend function: ";
   counter.print();
} // end main
Esempio n. 2
0
int main() {
	Count counter;

	counter.print();

	setX(counter, 8);

	counter.print();

	return 0;
}
Esempio n. 3
0
int main(int argc, const char *argv[]) {
    Count counter;

    std::cout << "counter.x after instantiation: ";
    counter.print();

    setX(counter, 8);
    std::cout << "counter.x after call to setX friend function: ";
    counter.print();

    return 0;
}
Esempio n. 4
0
int main(int argc, char **argv) {
    Count counter;
    Count *counterPtr = &counter;
    Count &counterRef = counter;

    counter.setX(1);
    counter.print();

    counterPtr->setX(2);
    counterPtr->print();

    counterRef.setX(3);
    counterRef.print();

    counter.print();
}
Esempio n. 5
0
int main()
{
   Count counter;                // create counter object 
   Count *counterPtr = &counter; // create pointer to counter
   Count &counterRef = counter;  // create reference to counter

   cout << "Assign 1 to x and print using the object's name: ";
   counter.x = 1;       // assign 1 to data member x
   counter.print();     // call member function print

   cout << "Assign 2 to x and print using a reference: ";
   counterRef.x = 2;    // assign 2 to data member x
   counterRef.print();  // call member function print

   cout << "Assign 3 to x and print using a pointer: ";
   counterPtr->x = 3;   // assign 3 to data member x
   counterPtr->print(); // call member function print

   return 0;  

} // end main
Esempio n. 6
0
int main(int argc, const char * argv[])
{
    Count counter;
    Count *counterPtr=&counter;
    Count &counterRef = counter;
    
    cout<<"Set counter to 1..\n";
    counter.setX(1);
    counter.print();
    
    cout<<"Set counter Ref to 2..\n";
    counterRef.setX(2);
    counter.print();
    
    cout<<"Set counter Ptr to 3..\n";
    counterPtr->setX(3);
    counterPtr->print();

    
    return 0;
}