 |
 |
C++ and PB
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
One more time, and please be very clear:
Can ProjectBuilder compile and can OS X run simple C++ apps that do everything C++ can even being object-oriented except use Cocoa APIs?
I am using 9 and CW for my CS class, but I want to reinstall the Beta and download the Dev Tools because I want to get using Cocoa and ObjC; but, I will not do this unless I can be certain that all of the apps I'll have to write in my class can be compiled in X with PB as surely as they could in 9 with CW!
Seriously, can C++ be compiled as long as it doesn't use Cocoa? and can I run any old C++ app in the terminal?
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: San Jose, CA USA
Status:
Offline
|
|
Yes, you can use C++ to build applications using Project Builder and run them on OS X. Heck, the Finder and parts of Carbon itself are written in C++. You can use Carbon, CoreFoundation, POSIX, Mach APIs ... anything but Cocoa. (It is possible to use C++ and Objective C in the same app but you have to define pure C APIs by which they can communicate; it's sort of ugly, but feasible if you have an existing C++ source base you want to use in a Cocoa app.)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
Haha moose, I just finished repliying to your post!
Thanks for the confirmation.
Anyone else want to chime in?
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Yup, you can surely use C++ in PB without any hassle.
If you don't want to use PB (but you'd still need the dev tools), you can edit a source file, then use the UN*X program c++ to compile (PB is just a front-end for the c++ program)
c++ is *basically* g++, with a few bugs in it. But those bugs wouldn't stop your CS programs.
C++ can do everything OO, like classes, polymorphism, &c.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
patricktaylor
|
|
<quote> C++ can do everything OO, like classes, polymorphism, &c./<quote>
This starts getting into language advocacy (and what was ever solved by arguing about that?)... but I can emphatically state that NO C++ CANNOT DO EVERYTHING OO (object-oriented).
[Before I get flammed I should point out that obviously C++ is usable in some form ... though it is the opinion of smarter people than I that much of the hassle and instability we associate with OSes and applications can be laid squarely at the feet of C++. ]
C++ has *some* features of an object-oriented language (classes, polymorphism, etc) that suggest that it falls into the tradition of OOPL, however it actually is an in-between language having more similarities with modular programming than with object-oriented. Yes, C++ is OOP but only if you ignore the intentions of the developers of the first fully functional OOP language, SmallTalk.
The classic and paradigmatic object-oriented programming language was SmallTalk. As Alan Kay said, "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." (Any old-time Mac fans will recognize Alan Kay as one of the most famous Apple Fellows and inventor of the Dynabook ... precursor to all notebook computers ).
Alan Kay did think that many of the now stereotypical features of OO were important, but he regretted that he didn't draw attention to the (in his opinion) two most important feature of Smalltalk-like (and hence object-oriented) languages: dynamism and messaging.
Objective C was an attempt to merge the philosophy of SmallTalk with the very popular C language. Unlike C++ which is neither dynamic nor message-passing, Objective C is squarely in the definition advanced by Alan Kay. Java is less so ... in part because of its emulation of C++, but at least it is messaging based.
In practice C++ became very popular so the definition of OOP was changed to include C++. This was a back-formation that allowed C++ in, not part of the original expression of the concept. Such is life. For a funny look at C++ and its many many problems, you can read this fake interview with the inventor of C++, Bjarne Stroustrup. http://www.wosource.com/bjarne_stroustrop.html
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
Well, to further support your point C++ looks to me like bubble-gum and bandaids of C to get it OO. Hence my interest in ObjC (that and the fact that it's Mac's language of choice.)
My question wasn't whether C++ had OO stuff, but whether I could use all of C++ stuffs, whether they be OO or not, in PB.
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
[see down below]
[This message has been edited by parallax (edited 02-01-2001).]
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
KewlMOTD
|
|
Everyone has their own taste of what is most syntactically pleasing. I for one consider the SmallTalk crap on top of C bubblegum and bandaids. Dynamism and the use of 'id' lead to the nasty habit of carelessness and type unsafety. Furthermore, can you really say Cocoa is a powerful flexible system when it's highly language-dependent because of the need for the ObjC runtime?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
Well, I understand there are preferences, but I, as a beginner, see that at least superficially and in the theory behind them ObjC is cleaner and more straightforward than C++.
Yes, that's just my opinion.
I am glad Apple made a break with tradition yet again in favor of quality.
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
KewlMOTD
|
|
What is it about C++ that you don't consider "OO"? There are late-binding and runtime type info features in C++, it's just that it's by "default" strongly-typed and early-binding for performance and efficiency reasons. Could you please further define "OO" and "modular" and why one is better than the other beyond their connotations?
[This message has been edited by KewlMOTD (edited 01-31-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
C++ and SmallTalk are really two "branches" of OOP. There's no real way of saying which is "the" OOPL. For CS courses, C++ is more than adequate. Saying that C++ doesn't do something that ObjC doesn't isn't fair: there may be superiority, but that's another issue.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
I really appreciate the fact that ObjC is C + a few keywords, whereas C++ is C + a huge honkin dictionary of them.
C++ probably has greter immediate power as a result, but that is less important to me than elegance, or a smooth and functional implementation. Can anyone say "Windows vs Mac"?
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
Oh, and I beleived you guys when you said I could do C++ in ProjectBuilder, so I deleted CodeWarrior and installed OS X and PB. I selected new project, C++ tool (should I have chosen carbon? I don't want GUI, just iostream and stuff.), put in my code, compiled, and ran it from the terminal. All went well. Thanks for being right.
Well, almost. I then rewrote my second C++ program in PB, and upon completion it errored that main()'s return type was no longer void but int. I don't know why, but I think this was because of my 'while' loop, which was the last thing in the program and ended on var=0. I never had 'return' anything!
But I changed it to int anyway. Who can argue with a compiler?
Also, this code:
cout<<"how old are you?"<<endl;
cout<<"input your number: ";
cin>>x;
gives me the prompt for the cin before asking me to input my number.
If I type:
cout<<"how old are you?"<<endl;
cout<<"input your number: "<<endl;
cin>>x;
it works as it should, but then it is impossible for me to have user input inline with output!
Is anyone familiar with the gcc compiler, and can tell me why this compiles incorrectly? Visual C++ does not do it this way!
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status:
Offline
|
|
The issue here is the buffering of streams. One side-effect of endl is that it flushes the output buffer. To get your prompt to show up without a newline you need to manually flush the buffer.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
It's not an issue of VC++ vs. g++. Standard C requires you to flush the buffer. Someone asked this question before on these forums, you may want to look through the threads for discussion on things like cin.ignore, etc.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
No, It's the compiler.
If I have this code:
cout<<"This program will convert your height from feet and inches into meters"<<endl;
cout<<"and your weight from pounds to kilograms"<<endl<<endl ;
cout<<"Please input the number of feet your height completely fills: ";
cin>>hf;
cout<<"Please input the remainder of your height in inches: ";
cin>>hi;
cout<<"Now please input your weight in pounds: ";
cin>>wp;
cout<<endl<<"Your height in meters is "<<convertHeight(hf,hi)<& lt;endl;
cout<<"Your weight in kilograms is "<<convertWeight(wp)<< endl;
I get THIS output (of all things...):
This program will convert your height from feet and inches into meters
and your weight from pounds to kilograms
5
10
150
Please input the number of feet your height completely fills: Please input the remainder of your height in inches: Now please input your weight in pounds:
Your height in meters is 2.1
Your weight in kilograms is 70.5
cin error my ass!
It's gcc! How do I fix it so it works NORMALLY? Please!
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
whoops.
[This message has been edited by Gametes (edited 02-02-2001).]
|
|
you are not your signature
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Geezus, just flush the buffer after the *last* cout you want to see on the screen.
Try something like
cout <<flush;
or cout.flush();
or something like that. Or just use endl after your prompts.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
I tried that, but it does nothing. The program still asks me for all 3 cins before giving me any couts! I searched the rest of the forums, and there was another thread that got to this unresolved point and then died.
I also looked on gcc.gnu.org and they didn't even address this issue, like it was "normal" somehow.
endl would be fine except I don't want a newline also.
Does anyone know how to:
a) configure gcc to compile like a rational, procedural compiler?
b) or revise my code (that would otherwise compile under all compilers known to man except gcc) so that I can cout output on the same line as I cin input (ex "What is your age?: 20")
This code:
cout<<"What is your weight? ";
cin>>weight;
does this:
150
What is your weight?
instead of:
What is your weight? 150
cout<<" "<<flush does nothing. cout.flush(), nothing. Only endl works, but then I get:
What is your weight?
150
Which is fine, except that it gives the programmer no choice, and it REQUIRES me to modify my code from other platforms. That kind of sucks for porting and compatibility, huh?
|
|
you are not your signature
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|