LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2013, 12:11 AM   #31
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124

Just to illustrate that C++ does not add to the functionality of C, here is an alternative way of extending structs and functions when dealing with pointers (ie when base_func is prototyped as void base_func(struct base_struct *b);):
Code:
struct extended_struct
{
   struct base_struct b;
   ... ... ... // extended bits
}

void extended_func(struct extended_struct *e)
{
   ... ... ...
   base_func(&(e->b));
   ... ... ...
}

Last edited by psionl0; 07-04-2013 at 10:34 PM.
 
Old 07-04-2013, 01:32 PM   #32
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Yes, there's a reason it was named C++. The real added value is automation of all of the messiness involved with alignment of base classes (especially virtual,) management of virtual functions, and templates. Those are all things the compiler takes care of, making it less likely that you'll make an error. Admittedly, those aren't runtime features, but not having preventable bugs is a runtime feature. You could, of course, also use asm instead of C.

Kevin Barry
 
Old 07-04-2013, 10:42 PM   #33
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by ta0kira View Post
The real added value is automation of all of the messiness involved with alignment of base classes (especially virtual,) management of virtual functions, and templates.
That was pretty much my original point. This automatic class management reduces the scope for miscommunication between team members and makes it easier to adapt library classes to suit your needs.

Of course, a C programmer would not normally adopt an "everything is an object" mentality as above and would use more efficient coding mechanisms.
 
Old 07-05-2013, 06:23 AM   #34
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by psionl0 View Post
...
Of course, a C programmer would not normally adopt an "everything is an object" mentality as above and would use more efficient coding mechanisms.
C++ is pretty far from this mentality. Or, pretty close . In C++, according to the standard, in dumbed down form an object is a memory area. I am serious.

I rather prefer to see the world through everything is a function, and we sometimes need to store state paradigm.

Last edited by Sergei Steshenko; 07-06-2013 at 09:24 AM.
 
Old 07-05-2013, 10:48 PM   #35
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by Sergei Steshenko View Post
C++ is pretty far from this mentality. Or, pretty close .
C++ is a little more flexible in how you approach a programming task.

Of course, even purely OOP languages like Java don't force you to think purely in terms of objects. For example, you wouldn't consider the java.lang.Math class to be an object but a set of mathematical functions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does making a class a 'friend' make the class' member classes 'friends'? Jusctsch Programming 7 11-17-2011 07:58 PM
C++ - Using class pointers to use class functions? golmschenk Programming 2 04-24-2011 12:41 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM
PHP: Calling class functions from another class. unreal128 Programming 5 11-24-2006 03:04 AM
C++ - problem with pointers to class member functions Nylex Programming 3 01-15-2006 10:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration