ENERGY 211 / CME 211 Lecture 30 December 5, 2008.

Slides:



Advertisements
Similar presentations
Operator overloading redefine the operations of operators
Advertisements

Overloading Operators Overloading operators Unary operators Binary operators Member, non-member operators Friend functions and classes Function templates.
A C LOSER L OOK AT C LASSES 1. A SSIGNING O BJECTS One object can be assigned to another provided that both objects are of the same type. It is not sufficient.
Operator Overloading Fundamentals
Chapter 14: Overloading and Templates
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
Object Oriented Programming C++. ADT vs. Class ADT: a model of data AND its related functions C++ Class: a syntactical & programmatic element for describing.
IT PUTS THE ++ IN C++ Object Oriented Programming.
Introduction to Effective C++ Programming Kwanghee Ko Design Laboratory Department of Ocean Engineering Massachusetts Institute of Technology Day 3.
Operatorsand Operators Overloading. Introduction C++ allows operators to be overloaded specifically for a user-defined class. Operator overloading offers.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Operator Overloading Operator Overloading allows a programmer to define new types from the built-in types. –Operator Overloading is useful for redefining.
Object Oriented Programming Elhanan Borenstein Lecture #3 copyrights © Elhanan Borenstein.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Classes, Arrays & Pointers. Compiler & Linker expectations file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler.
1 Introduction to Object Oriented Programming Chapter 10.
CSE1002 – Problem Solving with Object Oriented Programming
Yan Shi CS/SE 2630 Lecture Notes
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
Learning Objectives Pointers as dada members
Static data members Constructors and Destructors
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Motivation and Overview
Programming with ANSI C ++
Operator overloading Conversions friend inline
Operator Overloading Part 2
CS 2304: Operator Overloading
CISC181 Introduction to Computer Science Dr
Introduction to Classes
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
Class Operations Pointer and References with class types
Class: Special Topics Copy Constructors Static members Friends this
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Memberwise Assignment / Initialization
This pointer, Dynamic memory allocation, Constructors and Destructor
CSC 253 Lecture 8.
Automatics, Copy Constructor, and Assignment Operator
Introduction to Classes
CSC 253 Lecture 8.
Automatics, Copy Constructor, and Assignment Operator
Operator Overloading; String and Array Objects
Constructors and Other Tools
Copy Assignment CSCE 121 J. Michael Moore.
Indirection.
Operator Overloading, Friends, and References
CISC/CMPE320 - Prof. McLeod
Introduction of Programming
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Method of Classes Chapter 7, page 155 Lecture /4/6.
Linked Lists.
COP 3330 Object-oriented Programming in C++
A Deeper Look at Classes
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
ENERGY 211 / CME 211 Lecture 18 October 31, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Copy Assignment CSCE 121.
CS148 Introduction to Programming II
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
C++ support for Object-Oriented Programming
SPL – PS3 C++ Classes.
Object Oriented Programming
Introduction to Classes and Objects
Presentation transcript:

ENERGY 211 / CME 211 Lecture 30 December 5, 2008

Using Dynamic Libraries You can load dynamically-linked libraries from within your program and call their functions by name On UNIX, dlopen opens a library by its filename dlsym looks up a function by name and returns a pointer to it Can call function through the pointer! Must know argument and return types

Why Your Own Containers? If you need to maintain collections of objects that are linked in more complex ways than in lists or similar structures If you want to control memory allocation If you want to control which operations are made most efficient, at the expense of others you rarely or never need If the structure of your collection may change, but you don’t want to have to change other code that uses it

Keeping Classes to Yourself If you don’t want just anyone using a class of yours, then make its constructors and destructor private To allow particular classes to use it, declare them as friend classes inside its own definition, so you control which classes have access! Form: friend classname; It’s all-or-nothing: friend classes can access any private members

Overloading ++, -- To overload prefix ++, declare overload that takes no arguments if declared within a class, or one argument if not This overload must return a reference Make it increment, then return itself To overload postfix ++, add (unused) int argument, don’t return a reference Make it save itself, increment, then return original (saved) object

Overloading Dereferencing If a class serves as a wrapper class for an underlying object, you can overload * to support “dereferencing”, or extraction of the underlying object Implement one overload to return a const reference, which can’t be modified, and make function const too if it’s a member of a class Implement another overload to return a non-const reference

Next Time There is no next time, we’re done! Good luck finishing the project! Happy Holidays!