Jump to content

Nytro

Administrators
  • Posts

    18735
  • Joined

  • Last visited

  • Days Won

    710

Everything posted by Nytro

  1. Exploit Pack - An open source security framework Exploit Pack is an open source security framework developed by Juan Sacco. It combines the benefits of a Java GUI, Python as Engine and well-known exploits on the wild. It has an IDE to make the task of developing new exploits easier, instant search features and XML-based modules. A GPL license for the entire project helps to ensure the code will remain free. It also features a ranking system for contributors, tutorials for everyone who wants to learn how to create new exploits and a community to call for help. Why use Exploit Pack? It has a module editor that allows you to create your own custom exploits. There is an instant search feature built-in on the GUI for easier access to modules. Modules use XML DOM, so they are really easy to modify. It uses Python as its Engine because the language is more widely used on security related programming. A tutorial is also provided. If you want to earn money, they will pay you for each module you add to Exploit Pack. Download: http://exploitpack.com/download-framework Sursa si video: Exploit Pack - An open source security framework ~ THN : The Hacker News
  2. VIDEO: primul telefon cu ecran flexibil - Samsung Galaxy Skin de Radu Eftimie | 4 octombrie 2011 Samsung Galaxy Skin reprezinta ultima frontiera in lumea telecom si o noua incercare a sud-coreenilor de a detrona Apple: device-ul va avea un display AMOLED care ii va permite sa se plieze in jurul unui cilindru cu grosimea de 1 inci. Display-ul foloseste un strat de poliamida in loc de sticla. Dar, materialul cel mai important care a facut posibila realizarea acestui telefon, chiar si ca prototip, este grafenul, care este cunoscut drept materialul "minune". Grafenul este cel mai rezistent material din lume (de 200 de ori mai rezistent decat otelul), potrivit cercetatorilor de la universitatea Columbia. Ca specificatii tehnice, Galaxy Skin va avea: - rezolutie de 800x480 pixeli - camera de 8 megapixeli - 1 GB de memorie RAM - procesor de 1,2 GHz Deocamdata este un concept. Lansarea unui astfel de telefon ar putea avea loc in a doua jumatate anului viitor. Iata un videoclip sugestiv cu noua "minune" cu care Samsung se pregateste sa cucereasca lumea in 2012: Sursa si video: VIDEO: primul telefon cu ecran flexibil - Samsung Galaxy Skin | Hit.ro
  3. Nytro

    Ajutor bot php

    Cu cURL trimiti datele de logare din formlar. La citirea datelor, va trebui sa salvezi headerele, e optiune pentru asta COOKIE_JAR cred, ca la urmatorul request sa fii logat. Apoi faci direct request catre startpage.php.
  4. Nytro

    Certificari

    Certificarile "care se respecta" nu se dau asa, aiurea, de acasa... Se asigura pe cat posibil ca nu ai informatiile din teste la indemana. Pana la urma, daca e asa, poti lua un examen chiar daca nu stii nimic, cat timp ai informatiile la indemana. Din cate stiu esti (d)in Germania. Acolo gasesti probabil multe sedii unde poti da multe certificari.
  5. VIDEO: Maine se lanseaza iPhone 5. Cum ar trebui sa arate? de Radu Eftimie | 3 octombrie 2011 Pentru ca iPhone 5 va fi cu siguranta lansat pe piata maine, ne-am gandit sa adunam cele mai vehiculate informatii care au aparut pana acum despre viitorul smartphone de la Apple si sa vi le prezentam. Ce asteapta fanii de la urmatoarea generatie de telefoane Apple? Procesor dual-core identic celui folosit pe tableta iPad 2, dar si memorie suficienta pentru orice... 1 GB RAM, ecranul ar trebui sa fie mai mare (de 3,7 sau 4 inci) dar cu aceeasi tehnologie - retina display. In plus, tot pasionatii Apple ar vrea ca telefonul sa nu fie mai gros de 8 mm si sa fie dotat cu o camera foto de 8 MP. Multi incercat sa propuna un design concret pentru iPhone 5 pe baza zvonurilor privind dotarile hardware ale telefonului. Mai jos puteti urmari cateva clipuri create pe baza informatiilor "scurse" pe net. Pe 4 octombrie, la ora 8 seara - ora Romaniei - vom afla care dintre aceste previziuni au fost adevarate. Sursa si videoclipuri: http://www.hit.ro/telefoane-mobile/Maine-se-lanseaza-iphone-5-Cum-ar-trebui-sa-arate
  6. S-a folosit de informatii publice, deci ar avea tot dreptul. Da, probabil exista persoane mai "smechere", dar nu s-au ocupat.
  7. Linux - Means Freedom [The Hacker News Magazine] Dear Readers, We here at The Hacker News were very humbled to be given the opportunity to celebrate 10 millions hits to the website. Wow! We are so very grateful for your support and as I told you last month, I don't think Hacking is going anywhere and neither are we!! Your feedback is very important to us. Feel free to send us your thoughts and desires for Hacking news. If you want to write an editorial, let us know. We'd love to include it next month. For now, we will see you in our daily and best wishes for a great month. Content of October Edition: Linux - Means Freedom How to make my Linux Secure ? Hackathon Insider Threads Vs Hackers Linux : How to Series by Alok Srivastav Window 8 - Touch the Future The Security Model of Window 8 Server Microsoft Security Development Cycle September Cyber Attacks Download: http://theevilhackerz.com/THN-oct2011.pdf http://theevilhackerz.com/THN-oct2011.rar Sursa: Linux - Means Freedom [The Hacker News Magazine] October 2011 Issue Released ~ THN : The Hacker News
  8. Kaspersky Lab, Kyrus Tech si Microsoft au inchis botnet-ul Hlux/Kelihos By Radu FaraVirusi(com) on October 3, 2011 Kaspersky Lab, Microsoft si compania IT Kyrus Tech au colaborat la desfasurarea operatiunilor de inchidere a retelei de computere-zombie Kelihos, initial numita Hlux de catre Kaspersky Lab. Botnet-ul, compus din aproximativ 40.000 de computere infectate, era folosit de catre infractorii cibernetici pentru a trimite miliarde de mesaje spam, a fura informatii personale, a lansa atacuri DDoS, precum si pentru alte activitati ilegale. Microsoft a initiat un proces impotriva a 24 de persoane aflate in spatele acestui botnet, actiune care a dus la inchiderea domeniilor de Internet folosite de serverele de comanda si control ale retelei. Initiativa Microsoft a fost sustinuta prin contributii din partea Kaspersky Lab si o declaratie directa din partea Kyrus Tech, care oferea informatii detaliate si dovezi despre Kelihos. Kaspersky Lab a jucat un rol important in dezactivarea botnet-ului, colaborand cu Microsoft inca de la inceputul anului 2011 si oferind informatii in timp real despre activitatea Kelihos. La momentul actual, Kaspersky Lab se asigura ca reteaua nu mai poate fi controlata de nimeni – specialistii companiei au modificat codul folosit in administrarea acesteia, au spart protocolul de comunicare, au descoperit vulnerabilitatile infrastructurii peer-to-peer si au dezvoltat instrumentele specifice pentru a o contracara. In momentul in care actiunea legala a Microsoft a condus la dezactivarea domeniilor de Internet folosite de atacatori, Kaspersky Lab a patruns in retea si a preluat-o sub administrarea sa. „Kaspersky Lab a avut un rol-cheie in aceasta operatiune, oferindu-ne informatii importante si detaliate, culese pe baza analizei tehnice si a intelegerii modului in care opereaza Kelihos”, spune Richard Boscovich, avocat in cadrul Microsoft Digital Crimes Unit. „Aceste informatii au contribuit la inchiderea cu succes a botnet-ului, dar au servit si ca probe in instanta. Le multumim pentru sustinere si pentru dorinta lor de a lupta pentru un Internet mai sigur”, completeaza acesta. „Din 26 septembrie, cand Kaspersky Lab a initiat operatiunea de infiltrare in botnet, acesta a fost inoperabil”, afirma Tillmann Werner, Senior Malware Analyst Kaspersky Lab Germania. „Calculatoarele-zombie comunica acum cu noi, de aceea putem initia, de exemplu, activitati pentru a descoperi numarul de infectii pentru fiecare tara. Pana acum, Kaspersky Lab a numarat 61.463 de adrese IP infectate si colaboreaza cu toti furnizorii de servicii Internet (ISP) implicati, pentru a avertiza administratorii retelelor cu privire la acestea”, incheie Werner. Kelihos este un botnet de tip peer-to-peer si este compus din mai multe straturi – „controllers”, „routers” si „workers”. „Controllers” sunt computerele presupuse a fi controlate de catre infractorii cibernetici. Acestea distribuie comenzi tuturor celorlalte unitati si supravegheaza structura dinamica a retelei peer-to-peer. „Routers” sunt masini infectate, care au adrese IP publice, si sunt utilizate pentru a trimite spam, a colecta adrese de e-mail, a fura date de autentificare din fluxul retelei si multe altele. Microsoft a anuntat ca a adaugat semnatura de detectie pentru malware-ul Kelihos in Malicious Software Removal Tool, distribuit prin serviciul de update automat, care a dus la dezinfectarea unui numar mare de computere. Kaspersky Lab colaboreaza in mod constant cu Microsoft, un exemplu recent in acest sens fiind operatiunea de identificare si eliminare a viermelui Stuxnet, folosit de hackeri pentru a controla infrastructura IT industriala a centralelor nucleare din Iran. Kaspersky Lab a initiat si un sondaj, prin intermediul caruia intreaba utilizatorii cum trebuie sa procedeze cu botnet-ul Kelihos, din moment ce are control asupra sa. Pentru a raspunde, accesati http://www.securelist.com/en/polls. Kaspersky Lab multumeste SURFnet pentru sustinere in derularea operatiunii de infiltrare in botnet-ul Kelihos. Sursa: http://www.faravirusi.com/2011/10/03/kaspersky-lab-kyrus-tech-si-microsoft-au-inchis-botnet-ul-hluxkelihos/
  9. Nytro

    Certificari

    Nu ai nevoie de cursuri, o carte cam e de ajuns, de obicei e specificata la informatiile despre examen. Si exista carti speciale pentru examenele de ceritificare, programe cu intrebari si multe altele...
  10. Nytro

    Certificari

    Eu am luat MCTS Windows Internals, costa cam 50 - 80 de dolari, nu mai stiu, eu l-am dat gratis cu voucher de la facultate (MSP - Microsoft Student Partners). Am invatat singur, cateva ore... Apoi am mers la un centru unde se pot da, sunt vreo 8 centre in Bucuresti. Ai deschisa doar o aplicatie si nu ai voie cu telefon, nimic. Pe web nu stiu decat de Cisco, dar nu am dat si nu cred ca poti da de acasa.
  11. Au mai primit 2 persoane VIP, persoane care au prezentat ceva la Defcamp. Nu spun inca despre cine e vorba, vom discuta...
  12. Sa nu mai vad link-uri catre adf.ly, la munca cu voi...
  13. A fost prea misto, abia astept editia urmatoare. Cand am timp scriu eu un mic "articol" despre tot, din perspectiva mea. @Paul4games - Ba cat de mare poate sa fie (nu stiu daca am mancat una mai mare, si am mancat multe...), nu am putut sa o mananc pe toata... Si poate sa fie de la foamea acuta, dar a fost al dracu de buna. @Hertz - Te-am huiduit putin la "premiere", ai cateva dedicatii, dar pana la urma au fost foarte bine gandite probele.
  14. Si, cine e Michael asta?
  15. Mysql.com hacked, serving malware Posted on 26.09.2011 Mysql.com has been hacked and is currently serving malware, Armorize warns. The company has detected the compromise through its website malware monitoring platform HackAlert, and has analyzed how the compromise of the site's visitors unfolds. The mysql.com website is injected with a script that generates an iFrame that redirects the visitors to http://truruhfhqnviaosdpruejeslsuy.cx.cc/main.php, where the BlackHole exploit pack is hosted. "It exploits the visitor's browsing platform (the browser, the browser plugins like Adobe Flash, Adobe PDF, etc, Java, ...), and upon successful exploitation, permanently installs a piece of malware into the visitor's machine, without the visitor's knowledge," say the researchers. "The visitor doesn't need to click or agree to anything; simply visiting mysql.com with a vulnerable browsing platform will result in an infection." What type of malware is served is still unknown, but the worrying thing is that currently only 9 percent of the AV solutions used by VirusTotal block it. It is, of course, impossible to say who the attackers are. The domain reached through the iFrame is registered to one Christopher J Klein from Miami and is located in Berlin, Germany. The domain serving the exploit and the malware is located in Stockholm, Sweden. The administrators of the mysql.com domain are being contacted, but the site is still up and compromised, say the researchers. According to Sucuri Security researchers, the site has been compromised via JavaScript malware that "infects a web site through a compromised desktop (with virus), where it steals any stored password from the FTP client and uses that to attack the site." Trend Micro researchers add that they have recently discovered a denizen of a Russian underground forum selling root access to some of the cluster servers of mysql.com and its subdomains, asking at least $3,000 for each access, and that they have notified mysql.com administrators of their discovery a week ago. Sursa: https://www.net-security.org/malware_news.php?id=1853
  16. Sa nu uitati sa va luati tricourile cu "Fan Nytro" :->
  17. E in regula, cine e interesat poate sa ii dea un PM.
  18. 1) E penibil sa faci pagina de Facebook pentru asa ceva 2) Trebuie sa fii psihopat sa iti bati joc de astfel de lucruri
  19. Asta sa insemne ziua securitatii? Si site-uri .ro? Ce mentalitate jegoasa, tampita...
  20. Superb, foarte inteligent.
  21. FBI Arrests Suspected LulzSec and Anonymous Hackers By Jana Winter Published September 22, 2011| FoxNews.com he FBI arrested two alleged members of the hacking collectives LulzSec and Anonymous on Thursday morning in San Francisco and Phoenix and secured charges against a third suspect from Ohio, the Justice Department confirmed Thursday. Search warrants were also being executed in New Jersey, Minnesota and Montana, an FBI official told FoxNews.com, which first reported the arrests. One individual was described as part of the LulzSec group, the other part of the group that calls itself Anonymous, the official said. Cody Kretsinger, a 23-year-old from Phoenix, was charged with conspiracy and the unauthorized impairment of a protected computer, according to the federal indictment unsealed Thursday morning. In another indictment, Christopher Doyon, 47, of Mountain View, Calif., and Joshua Covelli, 26, of Fairborn, Ohio, were charged with conspiracy to cause intentional damage to a protected computer, causing intentional damage to a protected computer and aiding and abetting. The indictment says both men participated in a "distributed denial of service" attack on Santa Cruz County, Calif.'s computer servers in 2010, causing them to go offline. It alleges that the attack was carried out by the People's Liberation Front, which is associated with hacking groups such as Anonymous. Kretsinger, who goes by the online name "recursion," is believed to be a current or former member of LulzSec and is accused of being involved in the hacking of Sony Pictures Entertainment. Kretsinger and other coconspirators are accused of using a hacking technique called a SQL injection to obtain confidential information from Sony's computer systems. According to the indictment, he and coconspirators distributed stolen information by posting it on LulzSec's website before announcing the attack on Twitter. In order to evade law-enforcement detection, Kretsinger erased the hard drives used to carry out the Sony attack, the indictment said. He is expected to appear in a Phoenix federal court Thursday afternoon. Members of the Los Angeles FBI field office also arrested an alleged member of Anonymous in San Francisco. The suspected hacker is homeless and alleged to have been involved in Santa Cruz County government website cyberattacks, an FBI official told FoxNews.com exclusively. That suspect appears to have been Doyon, though this couldn't be immediately confirmed Thursday night. LulzSec is a splinter group from the “hacktivist” collective Anonymous, a loose collection of cybersavvy activists inspired by WikiLeaks and its head Julian Assange to fight for Internet freedoms — along the way defacing websites, shutting down servers, and scrawling messages across screens web-wide. While Anonymous is largely a politically motivated organization, LulzSec’s attacks were largely done “for the lulz” — Internet slang meaning “for the fun of it.” Both groups have been targeted by the FBI and international law enforcement agencies in recent months. In July, FoxNews.com broke the news that 16 alleged Anonymous members had been arrested in the U.S. and the U.K. Several high profile leaders of the group have been arrested since, including two individuals believed to be among the founders of LulzSec — and who shared the online name "Kayla." The metropolitan police in London arrested the first alleged member of the LulzSec group on June 20, a 19-year-old teen named Ryan Cleary. Subsequent sweeps through Italy and Switzerland in early July led to the arrests of 15 more people, all between the ages of 15 and 28. The two groups are responsible for a broad spate of digital break-ins targeting governments and large corporations, including Japanese technology giant Sony, the U.S. Senate, telecommunications giant AT&T, Fox.com, and other government and private entities. Sursa: FBI Arrests Suspected LulzSec And Anonymous Hackers | Fox News
  22. Da, pretul ar trebui sa depinda de complexitatea site-urilor.
  23. E de incredere.
  24. Daca v-ar sfatui cineva sa bateti un luptator de K1, sa va bateti cu Kilmbo Slice sau vreun mascat, oameni cu pregatire de ani de zile si voi niste cacaciosi, ce ati face? Si aici ma refer la toti cu "te duci si ii bati pe cei 7 mai mari cu 4 ani decat tine si probabil mai bine facuti".
  25. C++ FAQs (Second Edition) Authors: - Marshall Cline - Greg Lomow - Mike Girou Data: May 2000 Contents I Preliminaries 1 1 Introduction 3 1.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 3 1.2 What are C++ FAQs? . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 Who is the target audience for this book? . . . . . . . . . . . . . 3 1.4 Is this a book about C++ per se? . . . . . . . . . . . . . . . . . 4 1.5 Why do developers need a guidebook for C++ and OO technology? 4 1.6 What kind of guidance is given in the answers to these FAQs? . . 5 1.7 What is the electronic FAQ and why buy this book when the electronic FAQ is free? . . . . . . . . . . . . . . . . . . . . . . . . 5 1.8 Why should you buy this edition if you already have a copy of the first edition? . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.9 What conventions are used in this book? . . . . . . . . . . . . . . 6 2 Basic C++ Syntax and Semantics 9 2.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 9 2.2 What are the basics of main()? . . . . . . . . . . . . . . . . . . . 9 2.3 What are the basics of functions? . . . . . . . . . . . . . . . . . . 10 2.4 What are the basics of default parameters? . . . . . . . . . . . . 10 2.5 What are the basics of local (auto) objects? . . . . . . . . . . . . 11 2.6 What are the basics of constructing objects using explicit parameters? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.7 What are the basics of dynamically allocated (new) objects? . . . 13 2.8 What are the basics of local objects within inner scopes? . . . . . 14 2.9 What are the basics of passing objects by reference? . . . . . . . 15 2.10 What are the basics of passing objects by value? . . . . . . . . . 16 2.11 What are the basics of passing objects by pointer? . . . . . . . . 17 2.12 What are the basics of stream output? . . . . . . . . . . . . . . . 18 2.13 What are the basics of stream input? . . . . . . . . . . . . . . . . 19 2.14 What are the basics of using classes that contain overloaded operators? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.15 What are the basics of using container classes? . . . . . . . . . . 21 2.16 What are the basics of creating class header files? . . . . . . . . . 22 2.17 What are the basics of defining a class? . . . . . . . . . . . . . . 23 2.18 What are the basics of defining member functions? . . . . . . . . 24 2.19 What are the basics of adding a constructor to a class? . . . . . . 25 2.20 What are the basics of adding a destructor to a class? . . . . . . 27 ii 2.21 What are the basics of defining a class that contains a pointer to an object allocated from the heap? . . . . . . . . . . . . . . . . . 28 2.22 What are the basics of global objects? . . . . . . . . . . . . . . . 30 2.23 What are the basics of throwing and catching exceptions? . . . . 32 2.24 What are the basics of inheritance and dynamic binding? . . . . 34 3 Understanding the Management Perspective 37 3.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 37 3.2 What is the core message of this chapter (and this book)? . . . . 37 3.3 Why are the managers in charge rather than the developers who understand technology? . . . . . . . . . . . . . . . . . . . . . . . 38 3.4 How can someone manager something they don’t understand? . . 39 3.5 What is the most common mistake on C++ and OO projects? . 39 3.6 What’s the “Software Peter Principle”? . . . . . . . . . . . . . . 40 3.7 Should an organization use OO on all its projects? . . . . . . . . 40 3.8 Can OO be ignored until it goes away? . . . . . . . . . . . . . . . 41 3.9 What OO language is best? . . . . . . . . . . . . . . . . . . . . . 41 3.10 What is the right approach to processes and tools? . . . . . . . . 42 3.11 What is the right approach with off-the-shelf class libraries and frameworks? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4 The Architectural Perspective 44 4.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 44 4.2 Why is software architecture important? . . . . . . . . . . . . . . 44 4.3 What should the architecture be based on, the problem being solved or the problem domain? . . . . . . . . . . . . . . . . . . . 45 4.4 Should the software architecture be based on the policy of the problem? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.5 Do customers ever change their requirements? . . . . . . . . . . . 47 4.6 Are stable requirements desirable? . . . . . . . . . . . . . . . . . 47 4.7 What is the key to planning for change? . . . . . . . . . . . . . . 47 4.8 What is a framework? . . . . . . . . . . . . . . . . . . . . . . . . 48 4.9 What is the “inversion of control” exhibited by frameworks? . . . 48 4.10 What is an extensible, domain-specific framework? . . . . . . . . 49 4.11 What characteristics make a framework extensible yet domainspecific? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 4.12 What happens if the domain analysis is incorrect? . . . . . . . . 50 4.13 How much effort should be expended to support change — that is, how much is extensibility worth? . . . . . . . . . . . . . . . . 50 4.14 How does an architect make the software architecture flexible? . 51 4.15 What is the secret to achieving reuse? . . . . . . . . . . . . . . . 52 II Object-Oriented Design 53 5 Object-Oriented Fundamentals 55 5.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 55 5.2 Why is the world adopting OO technology? . . . . . . . . . . . . 55 5.3 What are some of the benefits of using C++ for OO programming? 56 5.4 What are the fundamental concepts of object-oriented technology? 56 iii 5.5 Why are classes important? . . . . . . . . . . . . . . . . . . . . . 57 5.6 What is an object? . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5.7 What are the desirable qualities of an object? . . . . . . . . . . . 58 5.8 How are classes better than the three basic building blocks of procedural software? . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.9 What is the purpose of composition? . . . . . . . . . . . . . . . . 60 5.10 What is the purpose of inheritance? . . . . . . . . . . . . . . . . 61 5.11 What are the advantages of polymorphism and dynamic binding? 61 5.12 How does OO help produce flexible and extensible software? . . . 62 5.13 How can old code call new code? . . . . . . . . . . . . . . . . . . 62 5.14 What is an abstraction and why is it important? . . . . . . . . . 65 5.15 Should abstractions be user-centric or developer-centric? . . . . . 66 5.16 What’s the difference between encapsulation and abstraction? . . 66 5.17 What are the consequences of encapsulating a bad abstraction? . 67 5.18 What’s the value of separating interface from implementation? . 67 5.19 How can separating interface from implementation improve performance as well as flexibility? . . . . . . . . . . . . . . . . . . . 68 5.20 What is the best way to create a good interface to an abstraction? 69 5.21 How are get/set member functions related to poorly designed interfaces? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 5.22 Should there be a get and a set member function for each member datum? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 5.23 Is the real purpose of a class to export data? . . . . . . . . . . . 71 5.24 Should OO be viewed as data-centric? . . . . . . . . . . . . . . . 71 6 Specification of Observable Behavior 73 6.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 73 6.2 Should users of a member function rely on what the code actually does or on the specification? . . . . . . . . . . . . . . . . . . . . . 73 6.3 What are the advantages of relying on the specification rather than the implementation? . . . . . . . . . . . . . . . . . . . . . . 75 6.4 What are advertised requirements and advertised promises? . . . 76 6.5 How are the advertised requirements and advertised promises of the member functions specified? . . . . . . . . . . . . . . . . . . . 76 6.6 Why are changes feared in development organizations that don’t use specification? . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.7 How do developers determine if a proposed change will break existing code? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 6.8 What are the properties of a substitutable (backward compatible) change in a specification? . . . . . . . . . . . . . . . . . . . . . . 79 6.9 How can it be shown that the implementation of a member function fulfills its specification? . . . . . . . . . . . . . . . . . . . . . 80 6.10 Is it possible to keep the specification synchronized with the code? 81 7 Proper Inheritance 83 7.1 What is proper inheritance? . . . . . . . . . . . . . . . . . . . . . 83 7.2 What are the benefits of proper inheritance? . . . . . . . . . . . 84 7.3 What is improper inheritance? . . . . . . . . . . . . . . . . . . . 85 7.4 Isn’t the difference between proper and improper inheritance obvious? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 iv 7.5 Is substitutability based on what the code does or what the specification promises the code will do? . . . . . . . . . . . . . . . . . 86 7.6 Is it proper to revoke (hide) an inherited public: member function? 88 7.7 What is specialization? . . . . . . . . . . . . . . . . . . . . . . . . 88 7.8 What do subsets have to do with proper inheritance? . . . . . . . 89 8 Detecting and Correcting Improper Inheritance 90 8.1 Can improper inheritance wreck a project? . . . . . . . . . . . . 90 8.2 What’s the best way to learn how to avoid improper inheritance? 90 8.3 Is intuition a reliable guide to understanding proper inheritance? 91 8.4 Is an Ostrich a kind-of Bird? . . . . . . . . . . . . . . . . . . . 91 8.5 Should an overridden virtual function throw an exception? . . . . 93 8.6 Can an overridden virtual function be a no-op? . . . . . . . . . . 95 8.7 Why does C++ make it so hard to fix the Ostrich/Bird dilemma? 96 8.8 Should Circle inherit from Ellipse? . . . . . . . . . . . . . . . 97 8.9 What can be done about the asymmetric-circle dilemma? . . . . 99 8.10 What is the one issue in these FAQs that doesn’t seem to die? . 100 8.11 Should Stack inherit from List? . . . . . . . . . . . . . . . . . . 101 8.12 Is code reuse the main purpose of inheritance? . . . . . . . . . . 102 8.13 Is container-of-thing a kind-of container-of-anything? . . . . . . . 103 8.14 Is bag-of-apple a kind-of bag-of-fruit, assuming bag-of-fruit allows the insertion of any kind-of fruit? . . . . . . . . . . . . . . . . . . 104 8.15 Is parking-lot-for-cars a kind-of parking-lot-for-arbitrary-vehicles (assuming parking-lot-for-vehicles allows parking any kind-of vehicle? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 8.16 Is array-of Derived a kind-of Base? . . . . . . . . . . . . . . . . 108 8.17 Does the fact that an array-of Derived can be passed as an arrayof Base mean that arrays are bad? . . . . . . . . . . . . . . . . . 110 9 Error Handling Strategies 111 9.1 Is error handling a major source of fundamental mistakes? . . . . 111 9.2 How should runtime errors be handled in C++? . . . . . . . . . 111 9.3 What happens to objects in stack frames that become unwound during the throw/catch process? . . . . . . . . . . . . . . . . . . 112 9.4 What is an exception specification? . . . . . . . . . . . . . . . . . 112 9.5 What are the disadvantages of using return codes for error handling? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 9.6 What are the advantages of throw...catch? . . . . . . . . . . . 113 9.7 Why is it helpful to separate normal logic from exception handling logic? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 9.8 What is the hardest part of using exception handling? . . . . . . 117 9.9 When should a function throw an exception? . . . . . . . . . . . 118 9.10 What is the best approach for the hierarchy of exception objects? 120 9.11 How should exception classes be named? . . . . . . . . . . . . . . 121 9.12 Where do setjmp and longjmp belong in C++? . . . . . . . . . 122 10 Testing Strategies 123 10.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 123 10.2 What are the advantages of self-testing objects? . . . . . . . . . . 123 v 10.3 What are some common excuses people use for not building selftesting into their objects? . . . . . . . . . . . . . . . . . . . . . . 124 10.4 What will happen if techniques like those presented here are not used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 10.5 When is a class correct? . . . . . . . . . . . . . . . . . . . . . . . 125 10.6 What is behavioral self-testing? . . . . . . . . . . . . . . . . . . . 126 10.7 What is a class invariant? . . . . . . . . . . . . . . . . . . . . . . 128 10.8 Why should the invariant be captured explicitly? . . . . . . . . . 129 10.9 When should the testInvariant() member function be called? 130 10.10What can be done to ensure that an object doesn’t get blown away by a wild pointer? . . . . . . . . . . . . . . . . . . . . . . . 130 III Language Facilities 133 11 References 135 11.1 What is a reference? . . . . . . . . . . . . . . . . . . . . . . . . . 135 11.2 What does “referent” mean? . . . . . . . . . . . . . . . . . . . . 136 11.3 When can a reference be attached to its referent? . . . . . . . . . 136 11.4 What happens when a value is assigned to a reference? . . . . . . 136 11.5 What is a local reference? . . . . . . . . . . . . . . . . . . . . . . 137 11.6 What does it mean to return a reference? . . . . . . . . . . . . . 137 11.7 What is the result of taking the address of a reference? . . . . . . 138 11.8 Can a reference be made to refer to a different referent? . . . . . 139 11.9 Why use references when pointers can do everything references can do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 11.10Aren’t references just pointers in disguise? . . . . . . . . . . . . . 140 11.11When are pointers needed? . . . . . . . . . . . . . . . . . . . . . 140 11.12Why do some people hate references? . . . . . . . . . . . . . . . . 141 11.13Does int& const x make sense? . . . . . . . . . . . . . . . . . . 141 12 New and Delete 143 12.1 Does new do more than allocate memory? . . . . . . . . . . . . . 143 12.2 Why is new better than good old trustworthy malloc()? . . . . . 143 12.3 Does C++ have a counterpart to realloc() that goes along with new and delete? . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 12.4 Can pointers returned from new be deallocated with free()? Can pointers returned from malloc() be deallocated with delete? . 144 12.5 Does delete p delete the pointer p or the referent *p? . . . . . . 144 12.6 Should the pointer returned from new Fred() be checked to see if it is NULL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 12.7 How can new be convinced to return NULL rather than throw an exception? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 12.8 How can new be set up to automatically flush pools of recycled objects whenever memory runs low? . . . . . . . . . . . . . . . . 146 12.9 What happens if delete p is called when p is NULL? . . . . . . . 149 12.10What happens when a pointer is deleted twice? . . . . . . . . . . 150 12.11How can an array of things be allocated and deallocated? . . . . 150 12.12What if delete p (not delete[] p) is used to delete an array allocated via new Fred[n]? . . . . . . . . . . . . . . . . . . . . . 151 vi 12.13Can the [] of delete[] p be dropped when p points to an array of some built-in type such as char? . . . . . . . . . . . . . . . . . 151 12.14How is an object constructed at a predetermined position in memory? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 12.15How can class Fred guarantee that Fred objects are created only with new and not on the stack? . . . . . . . . . . . . . . . . . . . 153 12.16How are objects created by placement new destroyed? . . . . . . 154 12.17In p = new Fred(), does the Fred memory “leak” if the Fred constructor throws an exception? . . . . . . . . . . . . . . . . . . 155 12.18Is it legal (and moral) for a member function to say delete this?156 12.19After p=new Fred[n], how does the compiler know that there are n objects to be destructed during delete[] p? . . . . . . . . . . 157 13 Inline Functions 158 13.1 What is the purpose of inline functions? . . . . . . . . . . . . . 158 13.2 What is the connection between the keyword “inline” and “inlined” functions? . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 13.3 Are there any special rules about inlining? . . . . . . . . . . . . . 159 13.4 What is the one-definition rule (ODR)? . . . . . . . . . . . . . . 159 13.5 What are some performance considerations with inline functions?160 13.6 Do inlined functions improve performance? . . . . . . . . . . . . 160 13.7 Do inlined functions increase the size of the executable code? . . 162 13.8 Why shouldn’t the inlining decision be made when the code is first written? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 13.9 What happens when a programmer uses an inlined function obtained from a third party? . . . . . . . . . . . . . . . . . . . . . . 163 13.10Is there an easy way to swap between inline and non-inline code? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 14 Const Correctness 167 14.1 How should pointer declarations be read? . . . . . . . . . . . . . 167 14.2 How can C++ programmers avoid making unexpected changes to objects? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14.3 Does const imply runtime overhead? . . . . . . . . . . . . . . . . 169 14.4 Does const allow the compiler to generate more efficient code? . 169 14.5 Is const correctness tedious? . . . . . . . . . . . . . . . . . . . . 169 14.6 Why should const correctness be done sooner rather than later? 170 14.7 What’s the difference between an inspector and a mutator? . . . 171 14.8 When should a member function be declared as const? . . . . . 171 14.9 Does const apply to the object’s bitwise state or its abstract state?172 14.10When should const not be used in declaring formal parameters? 173 14.11When should const not be used in declaring a function return type? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.12How can a “nonobservable” data member be updated within a const member function? . . . . . . . . . . . . . . . . . . . . . . . 175 14.13Can an object legally be changed even though there is a const reference (pointer) to it? . . . . . . . . . . . . . . . . . . . . . . . 176 14.14Does const cast mean lost optimization opportunities? . . . . . 177 vii 15 Namespaces 178 15.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 178 15.2 What is a namespace? . . . . . . . . . . . . . . . . . . . . . . . . 178 15.3 How can code outside a namespace use names declared within that namespace? . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 15.4 What happens if two namespaces contain the same name? . . . . 180 15.5 What are some of the rules for using namespaces? . . . . . . . . 181 15.6 What is name lookup? . . . . . . . . . . . . . . . . . . . . . . . . 182 15.7 What are the tradeoffs between the various techniques for using names from a namespace, particularly the standard namespace? . 182 15.8 Can namespaces break code? . . . . . . . . . . . . . . . . . . . . 183 15.9 Do namespaces have any other applications? . . . . . . . . . . . . 184 15.10How do namespaces solve the problem of long identifiers? . . . . 184 16 Using Static 185 16.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 185 16.2 What are static class members? . . . . . . . . . . . . . . . . . . . 185 16.3 What is an analogy for static data members? . . . . . . . . . . . 186 16.4 Can inline functions safely access static data members? . . . . 188 16.5 What is an analogy for static member functions? . . . . . . . . . 189 16.6 How is a static data member similar to a global variable? . . . . 191 16.7 How is a static member function similar to a friend function? . . 192 16.8 What is the named constructor idiom? . . . . . . . . . . . . . . . 192 16.9 How should static member functions be called? . . . . . . . . . . 193 16.10Why might a class with static data members get linker errors? . 194 16.11How is a const static data member initialized? . . . . . . . . . . 194 16.12What is the right strategy for implementing a function that needs to maintain state between calls? . . . . . . . . . . . . . . . . . . 195 16.13How can the function call operator help with functionoids? . . . 197 16.14Is it safe to be ignorant of the static initialization order problem? 198 16.15What is a simple and robust solution to the static initialization order problem? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 16.16What if the static object’s destructor has important side effects that must eventually occur? . . . . . . . . . . . . . . . . . . . . . 200 16.17What if the static object’s destructor has important side effects that must eventually occur and the static object must be accessed by another static object’s destructor? . . . . . . . . . . . . . . . . 201 16.18What are some criteria for choosing between all these various techniques? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 17 Derived Classes 205 17.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 205 17.2 How does C++ express inheritance? . . . . . . . . . . . . . . . . 205 17.3 What is a concrete derived class? . . . . . . . . . . . . . . . . . . 206 17.4 Why can’t a derived class access the private: members of its base class? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 17.5 How can a base class protect derived classes so that changes to the base class will not affect them? . . . . . . . . . . . . . . . . . 209 17.6 Can a derived class pointer be converted into a pointer to its public base class? . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 viii 17.7 How can a class Y be a kind-of another class X as well as getting the bits of X? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 17.8 How can a class Y get the bits of an existing class X without making Y a kind-of X? . . . . . . . . . . . . . . . . . . . . . . . . 211 17.9 How can a class Y be a kind-of another class X without inheriting the bits of X? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 18 Access Control 213 18.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 213 18.2 How are private:, protected:, and public: different? . . . . . 213 18.3 Why can’t subclasses access the private: parts of their base class?213 18.4 What’s the difference between the keywords struct and class? 214 18.5 When should a data member be protected: rather than private:?214 18.6 Why is private: the default access level for a class? . . . . . . . 215 19 Friend Classes and Friend Functions 216 19.1 What is a friend? . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 19.2 What’s a good mental model for friend classes? . . . . . . . . . . 217 19.3 What are some advantages of using friend classes? . . . . . . . . 218 19.4 Do friends violate the encapsulation barrier? . . . . . . . . . . . 218 19.5 What is a friend function? . . . . . . . . . . . . . . . . . . . . . . 218 19.6 When should a function be implemented as a friend function rather than a member function? . . . . . . . . . . . . . . . . . . . 219 19.7 What are some guidelines to make sure friend functions are used properly? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 19.8 What does it mean that friendship isn’t transitive? . . . . . . . . 220 19.9 What does it mean that friendship isn’t inherited? . . . . . . . . 222 19.10What does it mean that friends aren’t virtual? . . . . . . . . . . 223 19.11What qualities suggest a friend function rather than a member function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 19.12Should friend functions be declared in the private:, protected:, or public: section of a class? . . . . . . . . . . . . . . . . . . . . 227 19.13What is a private class? . . . . . . . . . . . . . . . . . . . . . . . 227 19.14How are objects of a class printed? . . . . . . . . . . . . . . . . . 229 19.15How do objects of a class receive stream input? . . . . . . . . . . 230 20 Constructors and Destructors 231 20.1 What is the purpose of a constructor? . . . . . . . . . . . . . . . 231 20.2 What is C++’s constructor discipline? . . . . . . . . . . . . . . . 231 20.3 What is the purpose of a destructor? . . . . . . . . . . . . . . . . 231 20.4 What is C++’s destructor discipline? . . . . . . . . . . . . . . . . 231 20.5 What happens when a destructor is executed? . . . . . . . . . . . 231 20.6 What is the purpose of a copy constructor? . . . . . . . . . . . . 231 20.7 When is a copy constructor invoked? . . . . . . . . . . . . . . . . 231 20.8 What is the “default constructor”? . . . . . . . . . . . . . . . . . 232 20.9 Should one constructor call another constructor as a primitive? . 232 20.10Does the destructor for a derived class need to explicitly call the destructor of its base class? . . . . . . . . . . . . . . . . . . . . . 232 20.11How can a local object be destructed before the end of its function?232 ix 20.12What is a good way to provide intuitive, multiple constructors for a class? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 20.13When the constructor of a base class calls a virtual function, why isn’t the override called? . . . . . . . . . . . . . . . . . . . . . . . 232 20.14When a base class destructor calls a virtual function, why isn’t the override called? . . . . . . . . . . . . . . . . . . . . . . . . . . 232 20.15What is the purpose of placement new? . . . . . . . . . . . . . . 232 21 Virtual Functions 233 21.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 233 21.2 What is a virtual member function? . . . . . . . . . . . . . . . . 233 21.3 How much does it cost to call a virtual function compared to calling a normal functions? . . . . . . . . . . . . . . . . . . . . . 233 21.4 How does C++ perform static typing while supporting dynamic binding? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 21.5 Can destructors be virtual? . . . . . . . . . . . . . . . . . . . . . 233 21.6 What is the purpose of a virtual destructor? . . . . . . . . . . . . 233 21.7 What is a virtual constructor? . . . . . . . . . . . . . . . . . . . 234 21.8 What syntax should be used when a constructor or destructor calls a virtual function in its project? . . . . . . . . . . . . . . . . 234 21.9 Should the scope operator :: be used when invoking virtual member functions? . . . . . . . . . . . . . . . . . . . . . . . . . . 234 21.10What is a pure virtual member function? . . . . . . . . . . . . . 234 21.11Can a pure virtual function be defined in the same class that declares it? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 21.12How should a virtual destructor be defined when it has no code? 234 21.13Can an ABC have a pure virtual destructor? . . . . . . . . . . . 234 21.14How can the compiler be kept from generating duplicate out-lined copies of inline virtual functions? . . . . . . . . . . . . . . . . . . 234 21.15Should a class with virtual functions have at least one non-inline virtual function? . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 22 Initialization Lists 236 22.1 What are constructor initialization lists? . . . . . . . . . . . . . . 236 22.2 What will happen if constructor initialization lists are not used? 236 22.3 What’s the guideline for using initialization lists in constructor definitions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 22.4 Is it normal for constructors to have nothing inside their body? . 236 22.5 How is a const data member initialized? . . . . . . . . . . . . . . 236 22.6 How is a reference data member initialized? . . . . . . . . . . . . 236 22.7 Are initializers executed in the same order in which they appear in the initialization list? . . . . . . . . . . . . . . . . . . . . . . . 237 22.8 How should initializers be ordered in a constructor’s initialization list? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 22.9 Is it normal for one member object to be initialized using another member object in the constructor’s initialization list? . . . . . . . 237 22.10What if one member object has to be initialized using another member object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 22.11Are there exceptions to the rule “Initialize all member objects in an initialization list”? . . . . . . . . . . . . . . . . . . . . . . . . 237 x 22.12How can an array of objects be initialized with specific initializers?237 23 Operator Overloading 238 23.1 Are overloaded operators like normal functions? . . . . . . . . . . 238 23.2 When should operator overloading be used? . . . . . . . . . . . . 238 23.3 What operators can’t be overloaded? . . . . . . . . . . . . . . . . 238 23.4 Is the goal of operator overloading to make the class easier to understand? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 23.5 Why do subscript operators usually come in pairs? . . . . . . . . 238 23.6 What is the most important consideration for operators such as +=, +, and =? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 23.7 How are the prefix and postfix versions of operator++ distinguished? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 23.8 What should the prefix and postfix versions of operator++ return?239 23.9 How can a Matrix-like class have a subscript operator that takes more than one subscript? . . . . . . . . . . . . . . . . . . . . . . 239 23.10Can a ** operator serve as an exponentiation operator? . . . . . 239 24 Assignment Operators 240 24.1 What should assignment operators return? . . . . . . . . . . . . 240 24.2 What is wrong with an object being assigned to itself? . . . . . . 240 24.3 What should be done about self-assignment? . . . . . . . . . . . 240 24.4 Should an assignment operator throw an exception after partially assigning an object? . . . . . . . . . . . . . . . . . . . . . . . . . 240 24.5 How should the assignment operator be declared in an ABC? . . 240 24.6 When should a user-defined assignment operator mimic the assignment operator that the compiler would generate automatically?240 24.7 What should be returned by private: and protected: assignment operators? . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 24.8 Are there techniques that increase the likelihood that the compilersynthesized assignment operator will be right? . . . . . . . . . . . 241 24.9 How should the assignment operator in a derived class behave? . 241 24.10Can an ABC’s assignment operator be virtual? . . . . . . . . . 241 24.11What should a derived class do if a base class’s assignment operator is virtual? . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 24.12Should the assignment operator be implemented by using placement new and the copy constructor? . . . . . . . . . . . . . . . . 241 25 Templates 242 25.1 What is the purpose of templates? . . . . . . . . . . . . . . . . . 242 25.2 What are the syntax and semantics for a class template? . . . . . 242 25.3 How can a template class be specialized to handle special cases? 244 25.4 What are the syntax and semantics for a function template? . . . 247 25.5 Should a template use memcpy() to copy objects of its template argument? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 25.6 Why does the compiler complain about >> when one template is used inside another? . . . . . . . . . . . . . . . . . . . . . . . . . 249 xi 26 Exception Tactics 251 26.1 What belongs in a try block? . . . . . . . . . . . . . . . . . . . . 251 26.2 When should a function catch an exception? . . . . . . . . . . . 251 26.3 Should a catch block fully recover from an error? . . . . . . . . . 252 26.4 How should a constructor handle a failure? . . . . . . . . . . . . 254 26.5 What are zombie objects (and why should they be avoided)? . . 254 26.6 What should an object do if one of its member objects could throw an exception during its constructor? . . . . . . . . . . . . . 255 26.7 Should destructors throw exceptions when they fail? . . . . . . . 257 26.8 Should destructors call routines that may throw exception? . . . 257 26.9 Should resource deallocation primitives signal failure by throwing an exception? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 26.10What should the terminate() function do? . . . . . . . . . . . . 258 26.11What should the unexpected() function do? . . . . . . . . . . . 259 26.12Under what circumstances can an overridden virtual member function throw exceptions other than those listed by the specification of the member function in the base class? . . . . . . . . 261 26.13How might the exception-handling mechanism cause a program to silently crash? . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 27 Types and RTTI 264 27.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 264 27.2 What is static type checking? . . . . . . . . . . . . . . . . . . . . 264 27.3 What is dynamic type checking? . . . . . . . . . . . . . . . . . . 265 27.4 What is the basic problem with dynamic type checking? . . . . . 267 27.5 How can dynamic type checking be avoided? . . . . . . . . . . . 267 27.6 Are there better alternatives to dynamic type checking? . . . . . 268 27.7 What is a capability query? . . . . . . . . . . . . . . . . . . . . . 269 27.8 What is an alternative to dynamic type checking with containers? 269 27.9 Are there cases where dynamic type checking is necessary? . . . 270 27.10Given a pointer to an ABC, how can the class of the referent be found? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 27.11What is a downcast? . . . . . . . . . . . . . . . . . . . . . . . . . 273 27.12What is an alternative to using downcasts? . . . . . . . . . . . . 274 27.13Why are downcasts dangerous? . . . . . . . . . . . . . . . . . . . 276 27.14Should the inheritance graph of C++ hierarchies be tall or short? 276 27.15Should the inheritance graph of C++ hierarchies be monolithic or a forest? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 27.16What is Runtime Type Identification (RTTI)? . . . . . . . . . . 277 27.17What is the purpose of dynamic cast<T>()? . . . . . . . . . . . 277 27.18Is dynamic cast<T>() a panacea? . . . . . . . . . . . . . . . . . 278 27.19What does static cast<T>() do? . . . . . . . . . . . . . . . . . 279 27.20What does typeid() do? . . . . . . . . . . . . . . . . . . . . . . 279 27.21Are there any hidden costs for type-safe downcasts? . . . . . . . 279 28 Containers 281 28.1 What are container classes and what are the most common mistakes made with container classes? . . . . . . . . . . . . . . . . . 281 28.2 Are arrays good or evil? . . . . . . . . . . . . . . . . . . . . . . . 282 xii 28.3 Should application development organizations create their own container classes? . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 28.4 What are some common mistakes with containers of pointers? . . 283 28.5 Does this mean that containers of pointers should be avoided? . . 283 28.6 Surely good old-fashioned char* is an exception, right? . . . . . 283 28.7 Can auto ptr<T> simplify ownership problems with containers of pointers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 28.8 Can a Java-like Object class simplify containers in C++? . . . . 284 28.9 What’s the difference between a homogeneous and a heterogeneous container? . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 28.10Is it a good idea to use a “best of breed” approach when selecting container classes? . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 28.11Should all projects use C++’s standardized containers? . . . . . 286 28.12What are the C++ standardized container classes? . . . . . . . . 286 28.13What are the best applications for the standardized C++ sequence container classes? . . . . . . . . . . . . . . . . . . . . . . 287 28.14What are the best situations for the standardized C++ associative container classes? . . . . . . . . . . . . . . . . . . . . . . . . 290 IV Topics 292 29 Mixing Overloading with Inheritance 294 29.1 What is the difference between overloaded functions and overridden functions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 29.2 What is the hiding rule? . . . . . . . . . . . . . . . . . . . . . . . 295 29.3 How should the hiding rule be handled? . . . . . . . . . . . . . . 298 29.4 What should a derived class do when it redefines some but not all of a set of overloaded member functions inherited from the base class? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 29.5 Can virtual functions be overloaded? . . . . . . . . . . . . . . . . 301 30 The Big Three 304 30.1 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 304 30.2 What are the Big Three? . . . . . . . . . . . . . . . . . . . . . . 304 30.3 What happens when an object is destroyed that doesn’t have an explicit destructor? . . . . . . . . . . . . . . . . . . . . . . . . . . 305 30.4 What happens if an object is copied but doesn’t have an explicit copy constructor? . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 30.5 What happens when an object that doesn’t have an explicit assignment operator is assigned? . . . . . . . . . . . . . . . . . . . 307 30.6 What is the Law of the Big Three? . . . . . . . . . . . . . . . . . 308 30.7 Which of the Big Three usually shows up first? . . . . . . . . . . 308 30.8 What is remote ownership? . . . . . . . . . . . . . . . . . . . . . 309 30.9 How is remote ownership special? . . . . . . . . . . . . . . . . . . 310 30.10What if a class owns a referent and doesn’t have all of the Big Three? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 30.11Are there any C++ classes that help manage remote ownership? 312 30.12Does auto ptr enforce the Law of the Big Three and solve the problems associated with remote ownership? . . . . . . . . . . . . 314 xiii 30.13Are there cases where one or two of the Big Three may be needed but not all three? . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 30.14Are there any other circumstances that might explicitly warrant the Big Three? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 30.15Why does copying an object using memcpy() cause a program crash? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 30.16Why do programs with variable-length argument lists crash? . . 318 30.17Why do programs that use realloc() to reallocate an array of objects crash? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 31 Using Objects to Prevent Memory Leaks 321 31.1 When are memory leaks important? . . . . . . . . . . . . . . . . 321 31.2 What is the easiest way to avoid memory leaks? . . . . . . . . . . 321 31.3 What are the most important principles for resource management?324 31.4 Should the object that manages a resource also perform operations that may throw exceptions? . . . . . . . . . . . . . . . . . . 325 31.5 Should an object manage two or more resources? . . . . . . . . . 326 31.6 What if an object has a pointer to an allocation and one of the object’s member functions deletes the allocation? . . . . . . . . 327 31.7 How should a pointer variable be handled after being passed to delete? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 31.8 What should be done with a pointer to an object that is allocated and deallocated in the same scope? . . . . . . . . . . . . . . . . . 328 31.9 How easy is it to implement reference counting with pointer semantics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 31.10Is reference counting with copy-on-write semantics hard to implement? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 31.11How can reference counting be implemented with copy-on-write semantics for a hierarchy of classes? . . . . . . . . . . . . . . . . 333 32 Wild Pointers and Other Devilish Errors 337 32.1 What is a wild pointer? . . . . . . . . . . . . . . . . . . . . . . . 337 32.2 What happens to a program that has even one wild pointer? . . 337 32.3 What does the compiler mean by the warning “Returning a reference to a local object”? . . . . . . . . . . . . . . . . . . . . . . 338 32.4 How should pointers across block boundaries be controlled? . . . 338 32.5 Is the reference-versus-pointer issue influenced by whether or not the object is allocated from the heap? . . . . . . . . . . . . . . . 339 32.6 When should C-style pointer casts be used? . . . . . . . . . . . . 340 32.7 Is it safe to bind a reference variable to a temporary object? . . . 341 32.8 Should a parameter passed by const reference be returned by const reference? . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 32.9 Should template functions for things like min(x,y) or abs(x) return a const reference? . . . . . . . . . . . . . . . . . . . . . . 342 32.10When is zero not necessarily zero? . . . . . . . . . . . . . . . . . 342 33 High-Performance Software 345 33.1 Is bad performance a result of bad design or bad coding? . . . . 345 33.2 What are some techniques for improving performance? . . . . . . 346 33.3 What is an advantage of using pointers and references? . . . . . . 347 xiv 33.4 What is a disadvantage of lots of references and pointers? . . . . 349 33.5 How else can member objects improve performance over pointers? 351 33.6 Which is better, ++i or i++? . . . . . . . . . . . . . . . . . . . . 351 33.7 What is the performance difference between Fred x(5); and Fred y = 5; and Fred z = Fred(5);? . . . . . . . . . . . . . . 353 33.8 What kinds of applications should consider using final classes and final member functions? . . . . . . . . . . . . . . . . . . . . . . . 354 33.9 What is a final class? . . . . . . . . . . . . . . . . . . . . . . . . . 354 33.10What is a final member function? . . . . . . . . . . . . . . . . . . 355 33.11How can final classes and final member functions improve performance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 33.12When should a nonfinal virtual function be invoked with a fully qualified name? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 33.13Should full qualification be used when calling another member function of the same class? . . . . . . . . . . . . . . . . . . . . . 358 33.14Do final classes and final member functions cause a lot of code duplication? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 33.15Why do some developers dislike final member functions and final classes? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 33.16Can a programming language — rather than just the compiler — affect the performance of software? . . . . . . . . . . . . . . . . . 361 34 COM and ActiveX 362 34.1 Who should read this chapter? . . . . . . . . . . . . . . . . . . . 362 34.2 What is the Component Object Model? . . . . . . . . . . . . . . 362 34.3 What are ActiveX and OLE? . . . . . . . . . . . . . . . . . . . . 363 34.4 What does the name Component Object Model mean? . . . . . . 364 34.5 What is a “binary object model”? . . . . . . . . . . . . . . . . . 364 34.6 What are the key features of COM? . . . . . . . . . . . . . . . . 365 34.7 What are GUIDs? . . . . . . . . . . . . . . . . . . . . . . . . . . 365 34.8 Why does COM need GUIDs (and CLSIDs and IIDs)? . . . . . . 367 34.9 What is an interface? . . . . . . . . . . . . . . . . . . . . . . . . . 367 34.10What is the IUnknown interface? . . . . . . . . . . . . . . . . . . 369 34.11How many ways are there to specify COM interfaces? . . . . . . 370 34.12What are COM classes and COM objects? . . . . . . . . . . . . . 372 34.13How hard is it for callers to create and use a COM object? . . . 376 34.14How does COM provide language transparency? . . . . . . . . . 378 34.15How does COM provide location transparency? . . . . . . . . . . 379 34.16What types of errors occur due to reference counting? . . . . . . 380 34.17What mechanism does COM define for error handling? . . . . . . 381 34.18How are interfaces versioned? . . . . . . . . . . . . . . . . . . . . 381 34.19Is COM object oriented? . . . . . . . . . . . . . . . . . . . . . . . 382 34.20What is the biggest problem with COM? . . . . . . . . . . . . . 383 34.21What are the major differences between COM and C++? . . . . 384 34.22What should a class be defined as a COM class? . . . . . . . . . 386 34.23What is Automation? . . . . . . . . . . . . . . . . . . . . . . . . 388 34.24What are dispatch interfaces? . . . . . . . . . . . . . . . . . . . . 388 34.25When should a class expose a Dispatch interface? . . . . . . . . . 389 34.26How does Automation work? . . . . . . . . . . . . . . . . . . . . 390 34.27How does Invoke accomplish all of this? . . . . . . . . . . . . . . 392 xv 34.28What is a type library? . . . . . . . . . . . . . . . . . . . . . . . 392 34.29What are the benefits of using type libraries? . . . . . . . . . . . 393 34.30How do type libraries improve performance? . . . . . . . . . . . . 394 34.31What are dual interfaces? . . . . . . . . . . . . . . . . . . . . . . 394 34.32What limitations are there on dual interfaces? . . . . . . . . . . . 395 34.33What are OLE custom controls and ActiveX controls? . . . . . . 396 34.34Why do ActiveX controls differ from OLE custom controls? . . . 397 34.35What is a control container? . . . . . . . . . . . . . . . . . . . . . 398 34.36What are component categories? . . . . . . . . . . . . . . . . . . 399 34.37What are events? . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 34.38What is DCOM? . . . . . . . . . . . . . . . . . . . . . . . . . . . 400 34.39How stable is DCOM’s infrastructure? . . . . . . . . . . . . . . . 401 34.40What is COM+? . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 35 Transitioning to CORBA 403 35.1 What is CORBA? . . . . . . . . . . . . . . . . . . . . . . . . . . 403 35.2 What is an ORB? . . . . . . . . . . . . . . . . . . . . . . . . . . 403 35.3 What is IDL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 35.4 What is COS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 35.5 What is OMA? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 35.6 What is OMG? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 35.7 What is the purpose of this chapter? . . . . . . . . . . . . . . . . 404 35.8 What is the most important message of this chapter? . . . . . . . 405 35.9 What are the important concepts behind CORBA? . . . . . . . . 405 35.10Isn’t OMG IDL pretty much the same as C++? . . . . . . . . . . 406 35.11Is the life cycle of a CORBA object the same as the life cycle of a C++ object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 35.12Is the C++ code that interacts with the CORBA implementation portable to a different CORBA vendor? . . . . . . . . . . . . . . 408 35.13How do CORBA exceptions compare to C++ exceptions? . . . . 408 35.14Which CORBA implementation is best? Is CORBA better than COM? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 36 C Language Considerations 410 36.1 What are the main issues when mixing C and C++ code in the same application? . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 36.2 How can C++ code call C code? . . . . . . . . . . . . . . . . . . 410 36.3 How can C code call C++ code? . . . . . . . . . . . . . . . . . . 411 36.4 Why is the linker giving errors for C functions called from C+ functions and vice versa? . . . . . . . . . . . . . . . . . . . . . . 412 36.5 How can an object of a C++ class be passed to or from a C function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 36.6 Can a C function directly access data in an object of a C++ class?414 36.7 Can C++ I/O (<iostream>) be mixed with C I/O (<stdio.h)? 415 36.8 Which is safer: <iostream> or <stdio.h>? . . . . . . . . . . . . 416 36.9 Which is more extensible: <iostream> or <stdio.h>? . . . . . . 416 36.10Which is more flexible: <iostream> or <stdio.h>? . . . . . . . . 416 36.11Why does it seem that C++ programming feels farther away from the machine than C? . . . . . . . . . . . . . . . . . . . . . . . . . 417 36.12Why does C++ do more things behind your back than C does? . 417 xvi 37 Private and Protected Inheritance 418 37.1 What are private inheritance and protected inheritance? . . . . . 418 37.2 What is the difference between private inheritance and protected inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 37.3 What is the syntax and semantics for private and protected inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 37.4 When should normal has-a be used, rather than private or protected inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . 421 37.5 What are the access rules for public, protected, and private inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 37.6 In a private or protected derived class, how can a member function that was public in the base class be made public in the derived class? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 37.7 Should a pointer be cast from a private or protected derived class to its base class? . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 38 Pointers to Member Functions 424 38.1 What is the type of a pointer to a nonstatic member function? . 424 38.2 Can pointers to nonstatic member functions be passed to signal handlers, X event call-back handlers, and so on, that expect Clike function pointers? . . . . . . . . . . . . . . . . . . . . . . . . 425 38.3 What is one of the most common errors when using pointers to member functions? . . . . . . . . . . . . . . . . . . . . . . . . . . 426 38.4 How is an array of pointers to nonstatic member functions declared?427 39 The Transition to OO and C++ 429 39.1 Who should read this chapter? . . . . . . . . . . . . . . . . . . . 429 39.2 What are the key messages of this chapter? . . . . . . . . . . . . 429 39.3 How many stages of technical expertise are there in the transition?430 39.4 Why bother defining levels of expertise? . . . . . . . . . . . . . . 430 39.5 Can OO/C++ be learned from a book? . . . . . . . . . . . . . . 431 39.6 Can OO/C++ be learned from a course? . . . . . . . . . . . . . 431 39.7 What is the key to learning OO/C++? . . . . . . . . . . . . . . 432 39.8 Are small projects a good way to get your feet wet? . . . . . . . 432 39.9 Does being a good C programmer help when learning OO/C++? 433 39.10What skills help when learning OO/C++? . . . . . . . . . . . . . 434 xvii Download: http://www.megaupload.com/?d=L1JWUMNO http://www.mediafire.com/?5r7o38pmm47s3m0 http://www.multiupload.com/O42Y08NUVF http://www.fileshare.ro/28930635804.8 http://www.girlshare.ro/2645981.8
×
×
  • Create New...