![]() |
| |||||||
| C++ Forum C++ Forum. C++ Programming |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
| |||
|
Notice: I declare the class Greeting, I then get to main where I declare an object Hello of class greeting, and since I used the constructor to do everything I wanted to do with it (or rather used the method Doit() which is renamed from my original constructor and called in the one which doesn't throw errors) I simply told the operating system my program was terminating normally (return 0 in Unix derivatives like Linux) and bailed. //Hello.cc Sample C++ program featuring an object with methods // uses a couple of kludges because my original constructor threw errors // from here to Samarkand. Compiled with GCC on June 14, 2008. #include <iostream> using namespace std; class Greeting{ char Name[40]; public: Greeting(){Doit();}; void Doit(); void Getname(); void Printname() {cout << "Hello " << Name << "!" << endl;} }; void Greeting: oit(){Getname(); Printname(); } void Greeting::Getname(){ cout << "What is your name? "; cin >> Name; } int main(){ Greeting Hello; return 0; } |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I program this into CSS? | green_eyed_goddess | CSS Forum | 0 | 08-24-2008 04:44 PM |
| program that the cpu can execute directly and a program that must be translated? | krnkinka | CPU Forum | 0 | 08-24-2008 04:20 PM |
| how to do program in php? | vicky | PHP Forum | 0 | 08-23-2008 10:04 PM |
| Spyware program detected 'Tagasaurus Trojan 'in Ccleaner program files? | Northman | Spyware Forum | 0 | 04-19-2008 09:01 AM |
| i need a program in php? | hireshire | PHP Forum | 0 | 01-06-2008 04:05 AM |