Click here to Skip to main content
15,918,211 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Troubling creating object Pin
AmorphousP22-Oct-04 9:37
AmorphousP22-Oct-04 9:37 
GeneralRe: Troubling creating object Pin
Maximilien22-Oct-04 9:51
Maximilien22-Oct-04 9:51 
GeneralRe: Troubling creating object Pin
AmorphousP22-Oct-04 10:34
AmorphousP22-Oct-04 10:34 
GeneralRe: Troubling creating object Pin
David Crow22-Oct-04 9:53
David Crow22-Oct-04 9:53 
GeneralRe: Troubling creating object Pin
AmorphousP22-Oct-04 10:29
AmorphousP22-Oct-04 10:29 
GeneralRe: Troubling creating object Pin
dharani26-Oct-04 22:44
dharani26-Oct-04 22:44 
GeneralRe: Troubling creating object Pin
AmorphousP27-Oct-04 9:51
AmorphousP27-Oct-04 9:51 
GeneralAbstract member functions - strange phenomenon open to discussion: Pin
Nick Nougat22-Oct-04 6:54
Nick Nougat22-Oct-04 6:54 
Hi!

I recently stumbled over this interesting phenomenon using abstract member functions:

The situation is this: We have an abstract base class that defines an interface. In the constructor of the base, a specific implementation dependent task needs to be carried out, so an abstract

member function is invoked in the constructor. The behaviour of this member function is defined by derived classes.
If no function body is provided for this abstract function in the base class, a linker error occurs (unresolved symbol). If we provide an empty body, in the base, everything links fine and the vtable

lookup correctly resolves the implementation of the deriving class.

The question is this: If the abstract function is resolved at run-time anyway, through use of vtables, why give me a compile-time error if I don't provide a body that will, due to it being an abstract

function, never be used in the first place?!
Is this a Microsoft specific behaviour bug/"feature", or is this standard ISO behaviour?
I compiled this using MS VS .NET 2003

Thanks for any thoughts about this.
Nick

Here is some exaple code for you to check it out:
<br />
#include <stdio.h><br />
class base<br />
{<br />
public:<br />
	base()<br />
	{<br />
		abstractFunction();<br />
	}<br />
	virtual ~base() {};<br />
<br />
	/* if you don't provide the function body<br />
	   with {}, a linker error occurs. Try uncommenting<br />
	   the part of the next line to make it work.<br />
	*/<br />
	virtual void abstractFunction() = 0 /*{}*/;<br />
};<br />
<br />
class derived : public base<br />
{<br />
public:<br />
	derived() {};<br />
	virtual ~derived() {};<br />
<br />
	// should be called by base::base()<br />
	void abstractFunction()<br />
	{<br />
		printf("works\n");<br />
	}<br />
} testInstance;	//create an instance right away...<br />


This code should print "works" to the console, since the

As soon as you uncomment the function body of base::abstractFunction(), everything will link fine and work as expected.
GeneralRe: Abstract member functions - strange phenomenon open to discussion: Pin
Roger Allen22-Oct-04 7:13
Roger Allen22-Oct-04 7:13 
GeneralRe: Abstract member functions - strange phenomenon open to discussion: Pin
Nick Nougat22-Oct-04 7:58
Nick Nougat22-Oct-04 7:58 
QuestionHow can I programmatically install a visual C++ add-in for visual C++? Pin
Behzad Ebrahimi22-Oct-04 5:56
Behzad Ebrahimi22-Oct-04 5:56 
GeneralPeek stdin Pin
peterchen22-Oct-04 5:50
peterchen22-Oct-04 5:50 
GeneralRe: Peek stdin Pin
David Crow22-Oct-04 6:04
David Crow22-Oct-04 6:04 
GeneralPlease help me with MFC Dialogs Pin
Member 214873122-Oct-04 5:22
Member 214873122-Oct-04 5:22 
GeneralRe: Please help me with MFC Dialogs Pin
David Crow22-Oct-04 5:33
David Crow22-Oct-04 5:33 
GeneralRe: Please help me with MFC Dialogs Pin
Member 214873122-Oct-04 5:34
Member 214873122-Oct-04 5:34 
GeneralRe: Please help me with MFC Dialogs Pin
David Crow22-Oct-04 5:37
David Crow22-Oct-04 5:37 
GeneralRe: Please help me with MFC Dialogs Pin
Buyer122-Oct-04 5:42
sussBuyer122-Oct-04 5:42 
GeneralRe: Please help me with MFC Dialogs Pin
David Crow22-Oct-04 5:46
David Crow22-Oct-04 5:46 
GeneralRe: Please help me with MFC Dialogs Pin
Buyer122-Oct-04 5:53
sussBuyer122-Oct-04 5:53 
GeneralRe: Please help me with MFC Dialogs Pin
David Crow22-Oct-04 5:57
David Crow22-Oct-04 5:57 
GeneralRe: Please help me with MFC Dialogs Pin
Buyer122-Oct-04 6:10
sussBuyer122-Oct-04 6:10 
GeneralRe: Please help me with MFC Dialogs Pin
David Crow22-Oct-04 6:14
David Crow22-Oct-04 6:14 
GeneralRe: Please help me with MFC Dialogs Pin
Buyer122-Oct-04 6:15
sussBuyer122-Oct-04 6:15 
Generalmetadata shell extension handler Pin
elda0122-Oct-04 5:06
elda0122-Oct-04 5:06 

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.