From: "Fernando Arturo G�mez Flores"
>From: Paul Herring
>> From: au veer [mailto:[EMAIL PROTECTED]
>>
>> [facetious answers to blatant homework questions=...]
[...]
>> >5. Is there something we can do in C but not in C++.
>>
>> Yes.
>>
>> >6. Difference Between Struct and Class.( atleast 2
>> >example)
>>
>> 1) the spelling
>> 2) the number of letters.
>>
>> One thing they have in common is that neither is a keyword
>> in C++ (or C for that matter) - neither should have a capital
>> letter in them.
[...]
>
>Hi,
>
>Answer to point five was unexpected to me. I thought that
>everything that
>you can do in C, you can do it also in C++. What are those things?
In the following two examples, the source code is identical - merely compiled
(or attempted) as either C or C++
Declare variable names that are keyword in C++ but not C.
=========================================================
$ type cpp.cpp
#include <stdio.h>
int main(void){
int old, new=3;
return 0;
}
$ make
cl cpp.cpp /EHs /Zc:forScope /Wall /W4 /WL /wd4820 /wd4619 /wd4217 /wd4710
/wd4668 /c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
cpp.cpp
cpp.cpp(3) : error C2059: syntax error : 'new'
make: *** [cpp.obj] Error 2
$ type c.c
#include <stdio.h>
int main(void){
int old, new=3;
return 0;
}
$ make
cl c.c /EHs /Zc:forScope /Wall /W4 /WL /wd4820 /wd4619 /wd4217 /wd4710 /wd4668
/c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
c.c
c.c(3) : warning C4101: 'old' : unreferenced local variable
c.c(3) : warning C4189: 'new' : local variable is initialized but not referenced
link c.obj /OUT:c.exe /nologo
$
Assume sizeof('a')==4:
======================
$ type c.c
#include <stdio.h>
int main(void){
printf("%d", sizeof('a'));
return 0;
}
$ c
4
$ type cpp.cpp
#include <stdio.h>
int main(void){
printf("%d", sizeof('a'));
return 0;
}
$ cpp
1
>And about point six, another difference, I think, is that by default, a
>class' members are private, wheras the struct's members are public.
I was refraining from giving too-useful answers in reply to the original post ;)
--
PJH
"...one of the main causes of the fall of the Roman Empire was that, lacking
zero, they had no way to indicate successful termination of their C programs."
- Robert Firth
Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272
Website : www.alderley.com Sales : [EMAIL PROTECTED] Service : [EMAIL
PROTECTED]
This email and its contents are confidential and are solely for the use of the
intended recipient. If you are not the original recipient you have received it
in error and any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited. Should you receive this email in error please
immediately notify [EMAIL PROTECTED]
This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
------------------------ Yahoo! Groups Sponsor --------------------~-->
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->
To unsubscribe : [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4968
Please do not reply to this message via email. More information here:
http://help.yahoo.com/help/us/groups/messages/messages-23.html
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/