Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373
|
|
- Edgar West
- 5 years ago
- Views:
Transcription
1 Arizona s First University. More ways to show off--controlling your Creation: IP and OO ECE 373
2 Overview Object Creation Control Distribution Possibilities Impact of design decisions on IP control 2
3 Good vs. Evil Advantages of Handles Clients have to only re-link to object code (recitative class) Hides all implementation from the end user (good for proprietary code) Clients do not waste time performing recompiles Disadvantages No member functions of the class can be inline All interface classes have this extra impl pointer One extra level of indirection Cost of creating/destroying the handle Evil will always triumph because GOOD is DUMB -- Spaceballs
4 Release-to-release binary compatibility (RRBC) Using old executable files (dll s and exe s) when portions of the system have changed Objective Adding new member functions or data members should not result in a required recompile You must follow guidelines to do this: Existing class hierarchy cannot change New virtual function declarations must come after the old ones All old virtual functions must remain in the same order (and cannot be deleted) Previously existing public and protected functions may not be deleted The total size of a class instance must remain the same
5 The Handle See, this is where the handles come in Put all of your changes in with this stuff that people never see Their size will always stay the same Our implementation can change as much as we like We can add member functions to our hearts content.
6 Object Creation Control My orders are to weed out all non-hackers who do not pack the gear to serve in my beloved Corps. Do you maggots understand that? 6
7 Object creation control Custom lists may have restrictions Lists of pointers Lists of objects that do not have copy constructors Restriction: DO NOT INSERT OBJECTS CREATED ON THE STACK Why was this? Because the objects get cleaned up when they move out of scope, and you re risking bad memory What did we say? It s hard to enforce that What is the truth? It s pretty easy to enforce that
8 What did I just do? #ifndef LEC25_DESTRUCTOR_H #define LEC25_DESTRUCTOR_H class PrivatePyle #include "destructor.h" public: #include <cstdio> void publicdelete( ) this->~privatepyle( ); // 3 of the big four are automagic private: ~PrivatePyle( ) ; #endif // LEC25_DESTRUCTOR_H /// shows off using a private destructor int main( void ) PrivatePyle gomer; return 0; Scanning dependencies of target example01 [ 96%] Building CXX object src/lectures/lec25/cmakefiles/example01.dir/example01.cpp.o /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/destructor.h: In function int main() : /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/destructor.h:10: error: PrivatePyle::~PrivatePyle() is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example01.cpp:7: error: within this context make[2]: *** [src/lectures/lec25/cmakefiles/example01.dir/example01.cpp.o] Error 1 make[1]: *** [src/lectures/lec25/cmakefiles/example01.dir/all] Error 2 make: *** [all] Error 2 8
9 So, again, what did I just do? Make the destructor private This means that when an object goes out of scope, it cannot be deleted Thus, stack created objects will not compile Heap created objects can be compiled, and should be deleted through some special function #include "destructor.h" #include <cstdio> /// shows off using a private destructor int main( void ) PrivatePyle *gomer = new PrivatePyle( ); gomer->publicdelete(); return 0;
10 Now, the converse How can you restrict usage of the new operator? The same way you get to Congress: Private Practice! #ifndef LEC28_INTHENEW_H #define LEC28_INTHENEW_H // cannot overload the 'new' operator without this header, in linux #include <cstddef> class InTheNew public: InTheNew( ) private: void* operator new( size_t size); void operator delete( void* address ); ; #endif //LEC28_INTHENEW_H
11 Implementation proof(s) #include "inthenew.h" /// shows off using a private new operator int main( void ) InTheNew *myobject = new InTheNew( ); delete myobject; return 0; Scanning dependencies of target example03 [ 98%] Building CXX object src/lectures/lec25/cmakefiles/example03.dir/example03.cpp.o /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h: In function int main() : /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h:12: error: static void* InTheNew::operator new(size_t) is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example03.cpp:6: error: within this context /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h:13: error: static void InTheNew::operator delete(void*) is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example03.cpp:6: error: within this context /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h:13: error: static void InTheNew::operator delete(void*) is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example03.cpp:6: error: within this context /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h:13: error: static void InTheNew::operator delete(void*) is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example03.cpp:7: error: within this context /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/inthenew.h:13: error: static void InTheNew::operator delete(void*) is private /Users/sprinkle/work/teaching/ece F/src/lectures/lec25/example03.cpp:7: error: within this context make[2]: *** [src/lectures/lec25/cmakefiles/example03.dir/example03.cpp.o] Error 1 make[2]: Target `src/lectures/lec25/cmakefiles/example03.dir/build' not remade because of errors. make[1]: *** [src/lectures/lec25/cmakefiles/example03.dir/all] Error 2 [100%] Built target example04 make[1]: Target `all' not remade because of errors. make: *** [all] Error 2 make: Target `default_target' not remade because of errors. 11
12 Implementation proof(s) (example04.cpp) #include "inthenew.h" #include <cstdio> /// shows off using a private new operator int main( void ) InTheNew myobject; return 0; [100%] Building CXX object src/lectures/lec25/cmakefiles/example04.dir/example04.cpp.o Linking CXX executable example04 [100%] Built target example04 But wait...the delete operator is private? How does this work? Of course...this is not the destructor, so the destructor is automatically generated by the compiler. 12
13 The funny thing... You know what the funny thing is about designing a class hierarchy, replete with class data members, virtual functions, complex attributed return values, and wanting to optimize it given a set of criteria? It s the little differences.
14 Homework 08 14
15 Quick and Easy Spec: Give me arbitrarily large sized integer arithmetic (no division) Be fast Be object-oriented Other details Obey all normal conventions for math (op overload) Give me bitwise abilities Dynamically allocate sizes Don t overflow, unless it is for the purpose of 2s complement arithmetic 15
16 Printing your results So, how would you print an arbitrarily large base 2 representation of an integer? b ? Or (in base 10) 16
17 More on printing in Base 10 In order to print a base 2 number in base 10 form, you need to do the standard 2^0 + 2^ transform, But you also need to be able to represent the base 10 number, which may be arbitrarily sized Rather than represent the base 10 number only as a string, we can do for base 10 what you will do for base 2 This is the hw08 library file, which will be provided online 17
18 How to use the hw08 library file #include "hpprinter.h"... string str = "b "; cout << str << " in base 10 is:" << endl; HPPrinter base10( str ); cout << base10 << endl; YOU will need to come up with a way to turn your class into an std::string, and then use the HPPrinter class to turn your string into a base 10 representation. How you do this is UP TO YOU!! How you write your tests is UP TO YOU!! The CMake command to test your file is UP TO YOU!! 18
19 How hw08 creates Objects So, given a way to control how objects are created, there is a specific need for this assignment: Here is a binary string, give me an HPInt base 10 representation of it Here is a binary number, give me an HPInt base 10 representation of it This can be done with just these two methods... Or, you can have object creation of base10 objects only be possible through these methods. 19
20 Example: // a fastlist for base_10_lists (i.e., fastlist) // // creates new base_10_list objects, when passed either a string, or an int // If the list already exists (based on the above-defined maps), then // fastlist returns the existing memory structure class fastlist friend class base_10_list; friend class base_10; private: // map of lists created from strings static listmap list; #ifdef FASTLIST_INT // map of lists created from ints static nlistmap nlist; #endif protected: // make these protected so no one can allocate objects // either using the stack, or the new operator fastlist( ); // destructor ~fastlist( ); // give me a list that represents this string static base_10_list* getlist( string str ); #ifdef FASTLIST_INT // give me a list that represents this int static base_10_list* getlist( int n ); #endif // log of the largest value we permit (e.g., the largest power) static float _rooflog; // the default unsigned base prefix static string _unsignedbaseprefix; ; The fastlist class, baby! What does it have that we want? Options (e.g., whether or not to use nfastlist) Speed (statically created, memory management)
21 Expensive operations Temporary Objects! Owww! You want to avoid these as much as possible Pass by const reference or by const * Do not create any temporary objects that you may need until after you ve done your conditional checks Use the copy constructor whenever possible You can always make this faster using copy-on-write
22 Examples: // good friend base_10_list operator +( const base_10_list& lhs, const base_10_list &rhs ) base_10_list result = lhs; return result += rhs; // bad friend base_10_list operator +( const base_10_list& lhs, const base_10_list &rhs ) base_10_list result; result = rhs; result += lhs; return result; 22
23 Proxies Almost, but not quite, exactly like copy-on-write Allows for the passing along of information from some master object that is big and should not be copied lightly, or should be centralized, due to data synchronicity Specifies what should be done to objects when information is written to the base Copy-on-write Specifies that a new object should always be created Pointers Specify that the existing object should be modified??? Specify that under certain conditions the existing object should be modified, but others it should be copied locally
24 Example: again, with the hw08 class HPInt_10 friend ostream& operator <<( ostream& out, const HPInt_10& me ); public: HPInt_10& operator =( HPInt_10 other ); HPInt_10( const HPInt_10& other ); HPInt_10( int val ); //... HPInt_10& operator-=( const HPInt_10 other ) //... snip *_list -= (*other._list); return *this; friend bool operator==( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return *lhs._list == (*rhs._list); friend bool operator!=( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return!(lhs == rhs); friend bool operator>( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return *lhs._list > (*rhs._list); 24
25 //... continued from previous page friend bool operator<( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return *lhs._list < (*rhs._list); friend bool operator>=( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return *lhs._list >= (*rhs._list); friend bool operator<=( const HPInt_10& lhs, const HPInt_10& rhs ) //... snip return *lhs._list <= (*rhs._list); //... lots more where this came from private: // this list is where all the magic happens base_10_list *_list; ; 25
26 Making complex from the simple When you are abstracting a system that has easy to understand functionality that builds on itself, take advantage of that Good example: comparative operators // not equal if equal returns false friend bool operator!=( const base_10_list& lhs, const base_10_list& rhs ) return!( lhs == rhs ); // <= if (not >) friend bool operator <=( const base_10_list& lhs, const base_10_list& rhs ) return!( lhs > rhs ); // >= if (not <) friend bool operator >=( const base_10_list& lhs, const base_10_list& rhs ) return!( lhs < rhs );
27 Distribution Possibilities Optimal delivery methods? 27
28 Remember the Alamo...uh, compile process 1. Preprocessor 2. Compiler 3. Linker 28
29 What can you do to protect your internal details? Distribute only compiled and linked code! Works for end users Distribute only compiled code Works for API users You still have to ship header files! How can you avoid putting all your info in header files? Distributed all your headers, and have all functions declared inline Now, you ve lost all your privacy! 29
30 Example: hiding impl in CPP #ifndef HAPPY_AND_FAST_H #define HAPPY_AND_FAST_H #include <string> class HappyAndFast public: // autogenerate the big four std::string getstring( ); ; #endif #include "happy-and-fast.h" std::string HappyAndFast::getString( ) return "This is my string"; Compile this as a library, and distribute the library files to potential users. Distribute this file, with no inlines 30
31 Class design impact Using handles/proxies can permit you to hide as much implementation as possible from the user Dynamic library loading (DLL) can allow you to not even have to recompile after libs are updated What are the downsides of distributing libraries? What happens if you want to distribute a templatized class? You re hosed! You can t hide this implementation because template classes cannot be distributed as binary? Why not?? 31
Mastering Data Abstraction or Get nit-picky on design advantages
Arizona s First University. Mastering Data Abstraction or Get nit-picky on design advantages Luke: Your not my father! Vader: You mean, You re not my father Luke: What? Vader: You used the possessive,
More informationArizona s First University. ECE 373. Operation Overloading. The Revolution Operation Will Be Televised (and, these slides will be online later today)
Arizona s First University. ECE 373 Operation Overloading The Revolution Operation Will Be Televised (and, these slides will be online later today) Previously, on ECE373 Families of operators can be overloaded
More informationthe gamedesigninitiative at cornell university Lecture 7 C++ Overview
Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationIII. Classes (Chap. 3)
III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationCSCI 123 Introduction to Programming Concepts in C++
CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe Brad Rippe More Classes and Dynamic Arrays Overview 11.4 Classes and Dynamic Arrays Constructors, Destructors, Copy Constructors Separation
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More informationIntroducing C++ to Java Programmers
Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003 1 Philosophy of C++ Bjarne Stroustrup invented C++ in the early 1980's at Bell Laboratories First called "C with classes" Design Goals:
More informationReliable C++ development - session 1: From C to C++ (and some C++ features)
Reliable C++ development - session 1: From C to C++ (and some C++ features) Thibault CHOLEZ - thibault.cholez@loria.fr TELECOM Nancy - Université de Lorraine LORIA - INRIA Nancy Grand-Est From Nicolas
More informationC++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University
C++ Review CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose of Review Review some basic C++ Familiarize us with
More informationLab 2: ADT Design & Implementation
Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted
More informationCome and join us at WebLyceum
Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad
More information2 ADT Programming User-defined abstract data types
Preview 2 ADT Programming User-defined abstract data types user-defined data types in C++: classes constructors and destructors const accessor functions, and inline functions special initialization construct
More informationComputer Science II CSci 1200 Lecture 18 Operators and Friends
Review from Lecture 17 Arrays and pointers Computer Science II CSci 1200 Lecture 18 Operators and Friends Different types of memory Dynamic allocation of arrays Today s Lecture Operators and Friends Chapter
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationMODERN AND LUCID C++ ADVANCED
Informatik MODERN AND LUCID C++ ADVANCED for Professional Programmers Prof. Peter Sommerlad Thomas Corbat Director of IFS Research Assistant Rapperswil, FS 2016 LIBRARY API/ABI DESIGN PIMPL IDIOM HOURGLASS
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationCh. 12: Operator Overloading
Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
More informationADTs & Classes. An introduction
ADTs & Classes An introduction Quick review of OOP Object: combination of: data structures (describe object attributes) functions (describe object behaviors) Class: C++ mechanism used to represent an object
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationC++ for System Developers with Design Pattern
C++ for System Developers with Design Pattern Introduction: This course introduces the C++ language for use on real time and embedded applications. The first part of the course focuses on the language
More informationVectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects
Vectors of Objects As we have mentioned earlier, you should almost always use vectors instead of arrays. If you need to keep track of persons (objects of class Person), you must decide what to store in
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationA brief introduction to C++
A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne
More informationCS11 Introduction to C++ Fall Lecture 7
CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,
More informationDue Date: See Blackboard
Source File: ~/2315/11/lab11.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 1 The purpose of this assignment is to become more familiar with
More informationReview: C++ Basic Concepts. Dr. Yingwu Zhu
Review: C++ Basic Concepts Dr. Yingwu Zhu Outline C++ class declaration Constructor Overloading functions Overloading operators Destructor Redundant declaration A Real-World Example Question #1: How to
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationP.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above
P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationSmart Pointers, deleted functions, and 2-3 trees
Smart Pointers, deleted functions, and 2-3 trees But first Any questions about your current homework assignment? Due Thursday night by 11:59pm Make-up oral exam: I will have a sign-up sheet on Thursday
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationPIC 10B Lecture 1 Winter 2014 Homework Assignment #3
PIC 10B Lecture 1 Winter 2014 Homework Assignment #3 Due Tuesday, February 4, 2014 by 5:00pm. Objectives: 1. To redefine the Big 3 : Copy constructor, Assignment operator, and Destructor for a class whose
More informationpointers & references
pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using
More informationPIC 10A Objects/Classes
PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous
More informationFor Teacher's Use Only Q No Total Q No Q No
Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9
More informationC++ 8. Constructors and Destructors
8. Constructors and Destructors C++ 1. When an instance of a class comes into scope, the function that executed is. a) Destructors b) Constructors c) Inline d) Friend 2. When a class object goes out of
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationMidterm Review. PIC 10B Spring 2018
Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded
More informationInheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization
Final Exam Overview: Monday, 3pm-6pm, in WLH 2005 First pages: Quiz question - No quiz of week 2 - No bit manipulation (shifting and masking) - Quizzes: week 4, 6, 8, 10 One page on C++ language features
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationCOMP322 - Introduction to C++ Lecture 01 - Introduction
COMP322 - Introduction to C++ Lecture 01 - Introduction Robert D. Vincent School of Computer Science 6 January 2010 What this course is Crash course in C++ Only 14 lectures Single-credit course What this
More informationAbsolute C++ Walter Savitch
Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationAbstraction in Software Development
Abstract Data Types Programmer-created data types that specify values that can be stored (type of data) operations that can be done on the values The user of an abstract data type (ADT) does not need to
More informationObject-Oriented Programming
- oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne
More informationDistributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes
Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented
More informationLecture 2. Binary Trees & Implementations. Yusuf Pisan
CSS 343 Data Structures, Algorithms, and Discrete Math II Lecture 2 Binary Trees & Implementations Yusuf Pisan Overview 1. Huffman Coding and Arithmetic Expressions 2. 342 Topics a. Pointers & References
More informationAIMS Embedded Systems Programming MT 2017
AIMS Embedded Systems Programming MT 2017 Object-Oriented Programming with C++ Daniel Kroening University of Oxford, Computer Science Department Version 1.0, 2014 Outline Classes and Objects Constructors
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More information内存管理. Memory management
内存管理 Memory management Review: Constructors Method that is called when an instance is created class Integer { public: int val; Integer() { val = 0; cout
More informationProgramming, numerics and optimization
Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationCSE 333 Midterm Exam July 24, Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationCh. 11: References & the Copy-Constructor. - continued -
Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed
More informationChapter 2. Procedural Programming
Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College November 9, 2016 Outline Outline 1 Chapter 9: C++ Classes Outline Chapter 9: C++ Classes 1 Chapter 9: C++ Classes Class Syntax
More informationFrom Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009
From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3 Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009 C++ Values, References, and Pointers 1 C++ Values, References, and Pointers 2
More informationObject-Oriented Programming for Scientific Computing
Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More informationException Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011
More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members
More informationSee the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I
Polynomial Class Polynomial(); Polynomial(const string& N, const vector& C); Polynomial operator+(const Polynomial& RHS) const; Polynomial operator-(const Polynomial& RHS) const; Polynomial operator*(const
More informationWhat will happen if we try to compile, link and run this program? Do you have any comments to the code?
1 # include < iostream > 2 3 int main () 4 { 5 std :: cout
More information7.1 Optional Parameters
Chapter 7: C++ Bells and Whistles A number of C++ features are introduced in this chapter: default parameters, const class members, and operator extensions. 7.1 Optional Parameters Purpose and Rules. Default
More informationPlan of the day. Today design of two types of container classes templates friend nested classes. BABAR C++ Course 103 Paul F. Kunz
Plan of the day Where are we at? session 1: basic language constructs session 2: pointers and functions session 3: basic class and operator overloading Today design of two types of container classes templates
More informationProgramming Abstractions
Programming Abstractions C S 1 0 6 B Cynthia Lee Topics du Jour: Make your own classes! (cont.) Last time we did a BankAccount class (pretty basic) This time we will do something more like the classes
More informationChapter 13: Introduction to Classes Procedural and Object-Oriented Programming
Chapter 13: Introduction to Classes 1 13.1 Procedural and Object-Oriented Programming 2 Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a
More informationCSCI-1200 Data Structures Fall 2018 Lecture 7 Templated Classes & Vector Implementation
CSCI-1200 Data Structures Fall 2018 Lecture 7 Templated Classes & Vector Implementation Announcements Lab 3 was a Frankenstein assembly of a new group exercise with part of a gdb lab. I hear many of you
More informationG52CPP C++ Programming Lecture 17
G52CPP C++ Programming Lecture 17 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Exceptions How to throw (return) different error values as exceptions And catch the exceptions
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationLecture 8. Xiaoguang Wang. February 13th, 2014 STAT 598W. (STAT 598W) Lecture 8 1 / 47
Lecture 8 Xiaoguang Wang STAT 598W February 13th, 2014 (STAT 598W) Lecture 8 1 / 47 Outline 1 Introduction: C++ 2 Containers 3 Classes (STAT 598W) Lecture 8 2 / 47 Outline 1 Introduction: C++ 2 Containers
More informationModern and Lucid C++ Advanced for Professional Programmers. Part 12 Advanced Library Design. Department I - C Plus Plus Advanced
Department I - C Plus Plus Advanced Modern and Lucid C++ Advanced for Professional Programmers Part 12 Advanced Library Design Thomas Corbat / Prof. Peter Sommerlad Rapperswil, 23.02.2017 HS2017 Topics
More informationLecture 7. Log into Linux New documents posted to course webpage
Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next
More informationNumber Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers
Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationReference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that
Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes
More information1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!
//Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new
More informationPractical C++ Programming
SECOND EDITION Practical C++ Programming Steve Oualline O'REILLY' Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo Preface xv Part I. The Basics 1. What Is C++? 3 A Brief History of C++ 3 C++
More informationObject Oriented Design
Object Oriented Design Chapter 9 Initializing a non-static data member in the class definition is a syntax error 1 9.2 Time Class Case Study In Fig. 9.1, the class definition is enclosed in the following
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationDue Date: See Blackboard
Source File: ~/2315/04/lab04.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 3 In this assignment create an IntegerSet class that will provide
More informationCSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington
CSE 333 Lecture 11 - constructor insanity Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia Exercises: - New exercise out today, due Monday morning
More informationObject-Oriented Programming in C++
Object-Oriented Programming in C++ Pre-Lecture 9: Advanced topics Prof Niels Walet (Niels.Walet@manchester.ac.uk) Room 7.07, Schuster Building March 24, 2015 Prelecture 9 Outline This prelecture largely
More informationCopying Data. Contents. Steven J. Zeil. November 13, Destructors 2
Steven J. Zeil November 13, 2013 Contents 1 Destructors 2 2 Copy Constructors 11 2.1 Where Do We Use a Copy Constructor? 12 2.2 Compiler-Generated Copy Constructors............................................
More informationOperators. The Arrow Operator. The sizeof Operator
Operators The Arrow Operator Most C++ operators are identical to the corresponding Java operators: Arithmetic: * / % + - Relational: < = >!= Logical:! && Bitwise: & bitwise and; ^ bitwise exclusive
More informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
More informationMore class design with C++ Starting Savitch Chap. 11
More class design with C++ Starting Savitch Chap. 11 Member or non-member function? l Class operations are typically implemented as member functions Declared inside class definition Can directly access
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationOverloaded Operators, Functions, and Students
, Functions, and Students Division of Mathematics and Computer Science Maryville College Outline Overloading Symbols 1 Overloading Symbols 2 3 Symbol Overloading Overloading Symbols A symbol is overloaded
More informationC++ Primer for CS175
C++ Primer for CS175 Yuanchen Zhu September 10, 2014 This primer is pretty long and might scare you. Don t worry! To do the assignments you don t need to understand every point made here. However this
More information