CS 32 Project 2 FAQ

CS 32 Project 2 FAQ - void S::g(S::N* n) . How can I test...

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

View Full Document Right Arrow Icon
Winter 2009 CS 32 Project 2 FAQ I'm thinking of implementing a private member function that returns a pointer to a nested class/struct. How do I do that? r Consider this: C class S { ... struct N { ... }; N* f(); ... }; N* S::f() // Error! Compiler doesn't recognize N. { ... } S::N* S::f() // Oh, S's N! This will compile. { ... } There's a C++ language rule that says roughly that the return type part of the definition of a member function of a class S isn't in the scope of S, so a name from S (like N) needs to be qualified (like S::N). Oddly enough, the parameter list is in the scope of S, so if S declared a function void g(N* n) , the implementation could begin void S::g(N* n) as well as
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: void S::g(S::N* n) . How can I test for memory leaks? That's a hard problem in general. If we limit it to checking whether we leak any linked list nodes, where each linked list node contains an object of the type stored in the Set, then we can do it this way: Declare the element type of the Set to be a special class we'll write, one that will keep track of all creations and deletions of objects of that special type. We can do this by instrumenting every constructor and the destructor of that special class. Then we run our tests and see if the number of destructions equals the number of constructions, as shown in some sample code ....
View Full Document

This note was uploaded on 11/07/2009 for the course CS 32 taught by Professor Davidsmallberg during the Winter '08 term at UCLA.

Page1 / 2

CS 32 Project 2 FAQ - void S::g(S::N* n) . How can I test...

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

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