From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fcc68f44249afbd4,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!m37g2000prh.googlegroups.com!not-for-mail From: markus034@gmail.com Newsgroups: comp.lang.ada Subject: Translating C++ class types into Ada tagged types? Date: Mon, 09 Jul 2007 18:39:47 -0700 Organization: http://groups.google.com Message-ID: <1184031587.650366.207550@m37g2000prh.googlegroups.com> NNTP-Posting-Host: 71.217.100.177 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1184031588 18885 127.0.0.1 (10 Jul 2007 01:39:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 10 Jul 2007 01:39:48 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: m37g2000prh.googlegroups.com; posting-host=71.217.100.177; posting-account=33NWdg0AAABVnogKP6r_3Ty2qFyOxx-9 Xref: g2news1.google.com comp.lang.ada:16443 Date: 2007-07-09T18:39:47-07:00 List-Id: Does ada fully support the object-orientedness? If so, how do i write (or translate) the following C++ object-oriented code into Ada object- oriented code? Without constractors: 1: // Demonstrates declaration of a class and 2: // definition of class methods, 3: 4: #include // for cout 5: 6: class Cat // begin declaration of the class 7: { 8: public: // begin public section 9: int GetAge(); // accessor function 10: void SetAge (int age); // accessor function 11: void Meow(); // general function 12: private: // begin private section 13: int itsAge; // member variable 14: }; 15: 16: // GetAge, Public accessor function 17: // returns value of itsAge member 18: int Cat::GetAge() 19: { 20: return itsAge; 21: } 22: 23: // definition of SetAge, public 24: // accessor function 25: // returns sets itsAge member 26: void Cat::SetAge(int age) 27: { 28: // set member variable its age to 29: // value passed in by parameter age 30: itsAge = age; 31: } 32: 33: // definition of Meow method 34: // returns: void 35: // parameters: None 36: // action: Prints "meow" to screen 37: void Cat::Meow() 38: { 39: cout << "Meow.\n"; 40: } 41: 42: // create a cat, set its age, have it 43: // meow, tell us its age, then meow again. 44: int main() 45: { 46: Cat Frisky; 47: Frisky.SetAge(5); 48: Frisky.Meow(); 49: cout << "Frisky is a cat who is " ; 50: cout << Frisky.GetAge() << " years old.\n"; 51: Frisky.Meow(); 52; return 0; 53: } Also the same code with constractors: 1: // Demonstrates declaration of a constructors and 2: // destructor for the Cat class 3: 4: #include // for cout 5: 6: class Cat // begin declaration of the class 7: { 8: public: // begin public section 9: Cat(int initialAge); // constructor 10: ~Cat(); // destructor 11: int GetAge(); // accessor function 12: void SetAge(int age); // accessor function 13: void Meow(); 14: private: // begin private section 15: int itsAge; // member variable 16: }; 17: 18: // constructor of Cat, 19: Cat::Cat(int initialAge) 20: { 21: itsAge = initialAge; 22: } 23: 24: Cat::~Cat() // destructor, takes no action 25: { 26: } 27: 28: // GetAge, Public accessor function 29: // returns value of itsAge member 30: int Cat::GetAge() 31: { 32: return itsAge; 33: } 34: 35: // Definition of SetAge, public 36: // accessor function 37: 38: void Cat::SetAge(int age) 39: { 40: // set member variable its age to 41: // value passed in by parameter age 42: itsAge = age; 43: } 44: 45: // definition of Meow method 46: // returns: void 47: // parameters: None 48: // action: Prints "meow" to screen 49: void Cat::Meow() 50: { 51: cout << "Meow.\n"; 52: } 53: 54: // create a cat, set its age, have it 55 // meow, tell us its age, then meow again. 56: int main() 57: { 58: Cat Frisky(5); 59: Frisky.Meow(); 60: cout << "Frisky is a cat who is " ; 61: cout << Frisky.GetAge() << " years old.\n"; 62: Frisky.Meow(); 63: Frisky.SetAge(7); 64: cout << "Now Frisky is " ; 65: cout << Frisky.GetAge() << " years old.\n"; 66; return 0; 67: }