Apr4&7.inheritance2

Apr4&7.inheritance2 - Managed vs. Unmanaged classes...

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

View Full Document Right Arrow Icon
Managed vs. Unmanaged classes Last time we saw a banking example that is a standard C++ class hierarchy Let's change things so that it uses a set of CLR classes – To do this we'll just insert the keyword ref in the class definitions – and what do you think will happen? Well … we get a bunch errors – 20 of them, to be exact, and they all look something like this: error C3222: 'AcctNum' : cannot declare default arguments for member functions of a managed type or generic functions So we get rid of all the default arguments in the constructors – To do this, we make constructors that give explicit values to the data members. Then we compile again – What happens now? We get some more errors 3 of them – they look something like this: error C2512: 'Checking' : no appropriate default constructor available
Background image of page 1

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

View Full DocumentRight Arrow Icon
Why did we get these errors? Error C3222 happened because we had code that looks like this: Checking (int AcctNum = 0000, int custID = 000, double Bal = 0, double Min = 1000, double Chg = .5); – Default values for arguments are not allowed for managed types or generic functions Error C2512 happened because we defined a constructor with an argument for each data member but did not define a no-argument (default) constructor for the classes – This is a problem because when an object of a derived type is declared, here is what happens: Default constructor for the basest base class is called Default constructor for the next-base class is called, etc. – This means that when a Checking object or a Savings is declared, the default constructor for BankAccount should be called and there isn't one – Similarly, when a SuperPlus object is declared, the default constructor for Checking should be called and there isn't one
Background image of page 2
Managed vs. Unmanaged classes If we are working in the CLR, there are some issues that are significant: – an unmanaged type cannot derive from a managed type – a ref class can only inherit from a ref class or interface class – the bottom line is that you need to keep a hierarchy compatible: all standard C++ or all CLR Working with managed types: – no default arguments are allowed for member functions of managed types or generic functions – this means that you have to make a default constructor that explicitly assigns the default values for data members instead of using the default argument syntax of standard C++ – it also may mean that you need some extra constructors for situations in which you may want to do some default, some supplied data member values (e.g. accounts and values in the banking example)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Multiple Inheritance • So far, we have just been dealing with single inheritance – the inherited class members can be traced back to a single base class • Multiple inheritance occurs when a class is derived from more than one base class – multiple inheritance is more complex and error prone that single inheritance what happens if both base classes have the same data member
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/30/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 31

Apr4&7.inheritance2 - Managed vs. Unmanaged classes...

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

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