bg287

csc210 20110328 Notes

Posted in csc210 by bnmng on 2011 03/28

Test 3 on April 6th.
69okProgram due date moved to the 11th.
Lab Wednesday at 5PM.
Homework assignment handout.
Answers to prev homework handed out.
Might want to bring both books to the test.

Today:
Homework then template functions.
Template Functions
Overloading (the alternative to template functions)
Defining the functions
Instantiating.

Composition:
The part after the colon in a inheritance constructor or composition constructor is called an initializer list.

Making virtual work
Formal parameter has to be from the base class.
Need the word virtual in the base class and need to pass by reference.

There will likely be a question like Chapter 15 Exam Prep #9.

+Template classes
Ipmlemtation file with a template class should not be named .cpp because it can’t be compiled.
A good idea is using

Example myclass.h

Example tempclass.template
template
simple::simple () {
value = 0;
}
void simple::setvalue (int n) {
value=n;
}
itemtype simple::getvalie () const {
return value;
}

Example:main.cpp
include
using namespace std;
#include “myclass.h”

*** examples are not complete *****
Review: changing a simple class to a template class
Don’t use .cpp for the implementation file.
Either tyep the implementation code into the .h file, or use #include.
Within class, the specification needs .
Every single function needs a template prefix.
Cleint functions that use the class need a template prefix.
Also need nameofclass::.

-Template classes

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: