Click here to Skip to main content
15,923,087 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPointer to another Window Pin
tjkrz10-Dec-03 7:00
tjkrz10-Dec-03 7:00 
GeneralRe: Pointer to another Window Pin
Antti Keskinen10-Dec-03 7:46
Antti Keskinen10-Dec-03 7:46 
GeneralRe: Pointer to another Window Pin
tjkrz10-Dec-03 8:44
tjkrz10-Dec-03 8:44 
GeneralRe: Pointer to another Window Pin
Antti Keskinen11-Dec-03 7:10
Antti Keskinen11-Dec-03 7:10 
GeneralRe: Pointer to another Window Pin
David Crow10-Dec-03 7:47
David Crow10-Dec-03 7:47 
GeneralRe: Pointer to another Window Pin
Joel Lucsy11-Dec-03 4:08
Joel Lucsy11-Dec-03 4:08 
GeneralRe: Pointer to another Window Pin
tjkrz15-Dec-03 9:21
tjkrz15-Dec-03 9:21 
Generaltemplate design question Pin
pankajdaga10-Dec-03 6:30
pankajdaga10-Dec-03 6:30 
Hi everyone,

I got myself a copy of Andrei Alexandrescu's Modern C++ Design after hearing a lot of good things about it. The book is on the heavy side though. I never used templates much before, but this book seems to open new vistas for great design.

I read the first chapter last night and was thinking about it the whole day. The topic of discussion being policy classes. Everything seemed fine, but I cannot understand one point:

He states that [B]Make the destructors of the policy classes protected and non-virtual[/B]

However, will this not lead to problems if someone instantiates a derived class through a base class:

Here is a small example, I am sure you guys have seen this millions of times. I, however, am a novice. So please advice:

Here is a small pseudo policy and a derived class:

<code>
template <class T>
class SuperBase
{
public:
virtual void OpenSource()
{
std::cout << "In superbase opensource" << std::endl;
}
};


template <class T>
class MyDataSource: public SuperBase<T>
{
public:
MyDataSource()
{
some = new T;
}

void OpenSource()
{
std::cout << "In mydatasource open source" << std::endl;
}
private:
T * some;

protected:
~MyDataSource()
{
std::cout << "In destructor of my source" << std::endl;
delete some;
}
};


Now, in my main program if I do this:

SuperBase<int> * temp = new MyDataSource<int>;
temp->OpenSource();
delete temp;
</code>

This will of course never call the destructor of MyDataSource.

Am I missing a design detail here. Are these templated classes never supposed to be derived from. How can I make sure such heritance is safe (in keeping with the design principle here).

Thanks a bunch.

Xargon

Without struggle, there is no progress
GeneralRe: template design question Pin
Jörgen Sigvardsson10-Dec-03 11:34
Jörgen Sigvardsson10-Dec-03 11:34 
GeneralRe: template design question Pin
pankajdaga10-Dec-03 12:50
pankajdaga10-Dec-03 12:50 
GeneralRe: template design question Pin
Andrew Walker10-Dec-03 12:44
Andrew Walker10-Dec-03 12:44 
GeneralRe: template design question Pin
pankajdaga10-Dec-03 12:52
pankajdaga10-Dec-03 12:52 
QuestionHyperthreading Windows API? Pin
solla10-Dec-03 6:03
solla10-Dec-03 6:03 
AnswerRe: Hyperthreading Windows API? Pin
valikac10-Dec-03 6:20
valikac10-Dec-03 6:20 
GeneralRe: Hyperthreading Windows API? Pin
solla10-Dec-03 6:24
solla10-Dec-03 6:24 
GeneralRe: Hyperthreading Windows API? Pin
David Crow10-Dec-03 8:50
David Crow10-Dec-03 8:50 
GeneralRe: Hyperthreading Windows API? Pin
solla11-Dec-03 1:43
solla11-Dec-03 1:43 
GeneralCreating and Using Static lib Pin
Anonymous10-Dec-03 5:31
Anonymous10-Dec-03 5:31 
GeneralRe: Creating and Using Static lib Pin
Larry J. Siddens10-Dec-03 6:00
Larry J. Siddens10-Dec-03 6:00 
GeneralRe: Creating and Using Static lib Pin
Chris Meech10-Dec-03 6:07
Chris Meech10-Dec-03 6:07 
GeneralMultithreading using _beginthread Pin
madmurdz10-Dec-03 4:54
madmurdz10-Dec-03 4:54 
GeneralRe: Multithreading using _beginthread Pin
Alexander M.,10-Dec-03 5:16
Alexander M.,10-Dec-03 5:16 
GeneralRe: Multithreading using _beginthread Pin
John M. Drescher10-Dec-03 5:38
John M. Drescher10-Dec-03 5:38 
GeneralRe: Multithreading using _beginthread Pin
valikac10-Dec-03 6:22
valikac10-Dec-03 6:22 
GeneralRe: Multithreading using _beginthread Pin
Jörgen Sigvardsson10-Dec-03 8:17
Jörgen Sigvardsson10-Dec-03 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.