473,793 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

paradox when constructor of an pure abstract base class called?

Hello All,

I have following doubt..

class abstractclass
{
public:
abstractclass() {}
virtual void method()=0;
};

class concreteclass:p ublic abstractclass
{
public:
concreteclass() {}
void method(){}
};

void main()
{

concreteclass c;
}

now when I create the object of concreteclass, the constructor of
abstractclass will be called.and as per the logic constructors are
called while creating the object,object of abstractclass is being
created..so how come we can create an object of a abstract class?
or to put in another way is there any paradox when the constructor of
an abstract class gets called?

Thanks and Regards,
Yogesh Joshi
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 19 '06
22 2415

"Francis Glassborow" <fr*****@robint on.demon.co.uk> wrote in message
news:Dm******** ******@robinton .demon.co.uk...
In article <MP************ *************** ***@arkansas.ne t>, Ralph
<nt************ *@yahoo.com> writes
It is also a reality that all implemented c runtimes today only accept a
'int' return to the OS (might not always be true - it would be up to the
vendor) and if one is not provided the implemenation dependent 'main()'
provides one for you. So the 'void' or 'int' return is only to provide thecompiler with a clue as to whether or not to generate a warning or error ifyour code does or doesn't include a return statement. Which is identical andproper compiler behavior when syntax-checking any function.


No, C++ explicitly allows the omission of a return statement from main
and specifies that in such a case 'falling off the end of main' is
implicitly a 'return 0'

There is absolutely no reason for not specifying the correct return type
(it even saves you a keystroke:-)


That is also a very interesting 'exception' for main(). Why should main() be
excluded from normal return checking?

-ralph

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 23 '06 #21
In article <QK************ ********@arkans as.net>, Ralph
<nt************ *@yahoo.com> writes
No, C++ explicitly allows the omission of a return statement from main
and specifies that in such a case 'falling off the end of main' is
implicitly a 'return 0'

There is absolutely no reason for not specifying the correct return type
(it even saves you a keystroke:-)


That is also a very interesting 'exception' for main(). Why should main() be
excluded from normal return checking?


Basically because it isn't a function in C++ but an entry point for a
program. Of course we could have just made it like a ctor and have no
return type but we were thinking of C compatibility and the advantage of
providing a mechanism for a status return.

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 24 '06 #22
Ralph wrote:
"Francis Glassborow" <fr*****@robint on.demon.co.uk> wrote in
message news:Dm******** ******@robinton .demon.co.uk...
In article <MP************ *************** ***@arkansas.ne t>, Ralph
<nt************ *@yahoo.com> writes
It is also a reality that all implemented c runtimes today
only accept a 'int' return to the OS (might not always be
true - it would be up to the vendor) and if one is not
provided the implemenation dependent 'main()' provides one
for you. So the 'void' or 'int' return is only to provide
the compiler with a clue as to whether or not to generate a
warning or error if your code does or doesn't include a
return statement. Which is identical and proper compiler
behavior when syntax-checking any function.

Not really. The point is that a program has to return a value
to the operating system somehow when it terminates. And int (or
a subset of int values) seems to be the universal type for this,
although on some systems, a 0 value was used to indicate failure
(whereas under Unix or Windows, 0 indicates success); on such
systems, the runtime will have to map the return values to
something else, since the standard requires return 0 to signify
success.

I don't quite understand your tirade about this: Windows and
Unix are fully identical in this respect.

In C, what often happened was that the program would call exit()
from some deeply nested function, and thus never "return" from
main. In C++, this is frowned upon, since it means that
destructors of the local variables are not called.

And of course, there are programs which never terminate
normally. I've worked on a lot of programs for Unix which are
automatically started in the initialization phase of booting,
and never stop. Arguably, "void main" makes sense for such
programs, but they seem to be more common under Unix than under
Windows.
No, C++ explicitly allows the omission of a return statement
from main and specifies that in such a case 'falling off the
end of main' is implicitly a 'return 0' There is absolutely no reason for not specifying the correct
return type (it even saves you a keystroke:-)

That is also a very interesting 'exception' for main(). Why
should main() be excluded from normal return checking?


Good question. The standard says that falling off the end of
main() is the equivalent of returning 0, and falling off the end
of any other function is undefined behavior.

Generally speaking, however, it's pretty rare that just
returning zero is appropriate behavior. You normally want to
inform the system whether the program has failed or not, so it
can take appropriate actions.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

Jan 24 '06 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2210
by: away | last post by:
Why some classes are seen to has their constructors declared as "protected"? Thanks!
11
2168
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain methods, such as public void Add(MyClass c). How can I enforce the same behavior (of requiring to implement a member with a new return type in an inherited class) in the master class (similar to the CollectionBase)? I have a class called...
10
1547
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the base class method is not to be abstract, and will be called if the instance was created as a 'generic' base class instance. It's sort of like I want the method to be abstract to children, but concrete at the base level. That way I can refer to...
4
5247
by: Jeff | last post by:
The derived class below passes a reference to an object in its own class to its base calss constructor. The code compiles and will run successfully as long as the base class constructor does not attempt to access the object -- since m_object is not actually created and initizialized until after the base constructor has been called. Any thoughts on the practice below? class Base { public:
10
4808
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a pure virtual function body
4
1877
by: Eric | last post by:
I was wondering what people thought about the information found at: http://g.oswego.edu/dl/mood/C++AsIDL.html Specifically, I am interested in the following recommendation: ---- Since interface classes cannot be directly instantiated, yet serve as virtual base classes for implementations, the constructors should take no arguments and should be listed as protected. Also, for similar
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.