The Difference Between C/++?
Moderator: Coders of Rage
The Difference Between C/++?
Well every time someone is explaining the difference between C and C++, I only hear: "C++ is object-oriented". Well I thought I'd give a small little post that explains the difference.
First off, every program starts with a "problem".
In C, these problems are broken down into functions(or methods) to solve these problems. Each function is usually quite short, and has a specific task. Structures are the tools to store your data with C. Throughout a C program, you'll build up many structures designed specifically to hold data for certain items within your programs, and your functions all throughout. This is procedural programming, everything is broken up into procedures so a problem can be more simply solved.
In C++, the structures and functions are combined into one: the object. In object-oriented programming, problems are broken down in a way objects can be made to match real life objects. You start this by using a class. a class can hold variables and methods, and the data can be private, public, or protected. With this, you could have a class Dog, then you could declare the dog Bash, and with the appropriate functions and data members you can make him bark, wag his tail, and so forth.
I hope this helped people who want to know the difference between these two languages. If I said something wrong, please tell me, or if there's something to include, also inform me.
This probably wasn't necessary but I was bored as hell xD
First off, every program starts with a "problem".
In C, these problems are broken down into functions(or methods) to solve these problems. Each function is usually quite short, and has a specific task. Structures are the tools to store your data with C. Throughout a C program, you'll build up many structures designed specifically to hold data for certain items within your programs, and your functions all throughout. This is procedural programming, everything is broken up into procedures so a problem can be more simply solved.
In C++, the structures and functions are combined into one: the object. In object-oriented programming, problems are broken down in a way objects can be made to match real life objects. You start this by using a class. a class can hold variables and methods, and the data can be private, public, or protected. With this, you could have a class Dog, then you could declare the dog Bash, and with the appropriate functions and data members you can make him bark, wag his tail, and so forth.
I hope this helped people who want to know the difference between these two languages. If I said something wrong, please tell me, or if there's something to include, also inform me.
This probably wasn't necessary but I was bored as hell xD
Re: The Difference Between C/++?
technically you can make structures with functions as member variables in C aswell.XianForce wrote:Well every time someone is explaining the difference between C and C++, I only hear: "C++ is object-oriented". Well I thought I'd give a small little post that explains the difference.
First off, every program starts with a "problem".
In C, these problems are broken down into functions(or methods) to solve these problems. Each function is usually quite short, and has a specific task. Structures are the tools to store your data with C. Throughout a C program, you'll build up many structures designed specifically to hold data for certain items within your programs, and your functions all throughout. This is procedural programming, everything is broken up into procedures so a problem can be more simply solved.
In C++, the structures and functions are combined into one: the object. In object-oriented programming, problems are broken down in a way objects can be made to match real life objects. You start this by using a class. a class can hold variables and methods, and the data can be private, public, or protected. With this, you could have a class Dog, then you could declare the dog Bash, and with the appropriate functions and data members you can make him bark, wag his tail, and so forth.
I hope this helped people who want to know the difference between these two languages. If I said something wrong, please tell me, or if there's something to include, also inform me.
This probably wasn't necessary but I was bored as hell xD
and you can also make data in structure "private". and actually you can also do pseudo inheritance with C.
the only thing that C cant do exactly is polymorphism. and honestly. i have never had the need for polymorphism, infact i dont
think i have ever used it other then trying some code out of a book.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
Re: The Difference Between C/++?
ehh, well I can see how it has its uses in classes with virtual functions and such...but not too far aside from that xDavansc wrote:technically you can make structures with functions as member variables in C aswell.XianForce wrote:Well every time someone is explaining the difference between C and C++, I only hear: "C++ is object-oriented". Well I thought I'd give a small little post that explains the difference.
First off, every program starts with a "problem".
In C, these problems are broken down into functions(or methods) to solve these problems. Each function is usually quite short, and has a specific task. Structures are the tools to store your data with C. Throughout a C program, you'll build up many structures designed specifically to hold data for certain items within your programs, and your functions all throughout. This is procedural programming, everything is broken up into procedures so a problem can be more simply solved.
In C++, the structures and functions are combined into one: the object. In object-oriented programming, problems are broken down in a way objects can be made to match real life objects. You start this by using a class. a class can hold variables and methods, and the data can be private, public, or protected. With this, you could have a class Dog, then you could declare the dog Bash, and with the appropriate functions and data members you can make him bark, wag his tail, and so forth.
I hope this helped people who want to know the difference between these two languages. If I said something wrong, please tell me, or if there's something to include, also inform me.
This probably wasn't necessary but I was bored as hell xD
and you can also make data in structure "private". and actually you can also do pseudo inheritance with C.
the only thing that C cant do exactly is polymorphism. and honestly. i have never had the need for polymorphism, infact i dont
think i have ever used it other then trying some code out of a book.
Re: The Difference Between C/++?
im not sure what you are trying to say. can you explain better. i dont know where you get virtual functions from.XianForce wrote:
ehh, well I can see how it has its uses in classes with virtual functions and such...but not too far aside from that xD
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: The Difference Between C/++?
avansc is saying that every problem that can be solved with an OO C++ approach can be solved with a procedural C approach. He's right.
Re: The Difference Between C/++?
Well I'ts like polymorphism + inheritance isn't it?avansc wrote:im not sure what you are trying to say. can you explain better. i dont know where you get virtual functions from.XianForce wrote:
ehh, well I can see how it has its uses in classes with virtual functions and such...but not too far aside from that xD
if you declare a function in a base class virtual, you can use overrided functions in the base class.
Re: The Difference Between C/++?
im still not sure what you are refering to. sorry.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: The Difference Between C/++?
He was saying "I can see how [C++] has uses with ... virtual functions and such"
And re:
fn will call class A's do(), not class B's. Which probably has its uses. Virtual prevents this (by binding the call to do() at run-time instead of compile-time). This is why you should always declare inheritance-related destructors as virtual, or you might destruct the wrong object and not deallocate any memory that B allocated.
EDIT:
The 'binding at run-time' step involved in the virtual keyword makes your program require more memory (definite, your program keeps a table of virtual functions and looks them up when its running) and probably has a speed hit, I'm not sure if it's negligible or not.
And re:
Also you can override a function without declaring it virtual, but if you do that...if you declare a function in a base class virtual, you can use overrided functions in the base class.
Code: Select all
class A {
do();
}
class B : public A {
do();
}
fn (A& aobj) {
A.do();
}
B bobj;
fn(B)
EDIT:
The 'binding at run-time' step involved in the virtual keyword makes your program require more memory (definite, your program keeps a table of virtual functions and looks them up when its running) and probably has a speed hit, I'm not sure if it's negligible or not.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: The Difference Between C/++?
That's also going to be slower than not using polymorphism. It's the overhead for doing the OO things such as this that makes C faster than C++. Just thought that I would point this out, as it is a C vs C++ thread.MarauderIIC wrote:by binding the call to do() at run-time instead of compile-time
Re: The Difference Between C/++?
okay i see what he is saying. yeah inheritance and polymorphism is really not on my list of important things to know. especially for game programming.
its a java thing that C++ tried to compete with, but in actuality its so very rarely used. i mean how many times have you ever used inheritance. and polymorphism.
there is nothing C++ can do that C cant do better.
(we have to define better, yeah C++ can do it in less lines of code, or maybe there is easy strings and you can make classes, but in performance, and portability, and just pure beauty C is hard to beat.)
its a java thing that C++ tried to compete with, but in actuality its so very rarely used. i mean how many times have you ever used inheritance. and polymorphism.
there is nothing C++ can do that C cant do better.
(we have to define better, yeah C++ can do it in less lines of code, or maybe there is easy strings and you can make classes, but in performance, and portability, and just pure beauty C is hard to beat.)
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
Re: The Difference Between C/++?
I always saw C++ as more manageable than C while not being necessary more powerful. C++ was made from C so you can technically do anything in C that you can in C++ but C++ standardizes object management. Both are important for different things.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: The Difference Between C/++?
Every time I do something with players and NPCs, I have an Actor class that has the common attributes.avansc wrote:i mean how many times have you ever used inheritance.
Only in that case, tbh :Pand polymorphism.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.