cs246-s11-001-june30

cs246-s11-001-june30 - CS 246(Spring 2011 Section 1...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Thursday 30 June Separate Compilation and Inheritance Happy Canada Day! (tomorrow)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 2 Today's Agenda Separate Compilation A few more tips for A4, Q2 Inheritance Implementation inheritance Type inheritance and Polymorphism Constructor / Destructor Copy constructor / assignment Midterm feedback (end of class)
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 3 2.23 Separate Compilation You have seen some of this in CS 136 Divide into interface and implementation Encapsulation Interface Prototype declarations Appears in one or more include files (.h) Implementation Actual declarations and code Appears in one or more source files (.cc)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 4 Source files Within a source (.cc) file, we can declare external variables and routines (i.e., outside of a routine or class scope) Implicitly global in scope Can encapsulate these using static Example: file1.cc int a; static int b; void fun1() { . . . } static void fun2() { . . . }
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 5 Include files Include files (.h) can use extern to indicate that the actual definition is located elsewhere Example: file2.h enum Colour {R, G, B}; // ? const double PI = 3.141; extern int a; extern int square(int a); class House { int numRooms; public: int getNumRooms(); };
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 6 Example (continued) file2.cc #include “file2.h” int a; static int y; int square(int a) { return a * a; } int House::getNumRooms() { return numRooms; } static void modifyValue() { x /= 2; }
Background image of page 6
CS 246 (Spring 2011) - Section 001 - Thursday 30 June 7 Example (continued) file2driver.cc #include “file2.h” int main() { House h; int x = 3; cout << square(x) << endl; }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2011 for the course CS 246 taught by Professor Wormer during the Spring '08 term at Waterloo.

Page1 / 22

cs246-s11-001-june30 - CS 246(Spring 2011 Section 1...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online