I was wondering if anyone new of a good classes tutorial, all the ones i found didn't explain them well enough, i am looking for a good in depth one that explains it step by step,
thanks in advance
Classes Tutorial
Page 1 of 112 Replies - 618 Views - Last Post: 06 September 2011 - 03:48 AM
Replies To: Classes Tutorial
#2
Re: Classes Tutorial
Posted 05 September 2011 - 07:38 AM
I also sucked at classes and grieved about it for about a full day before I created my own reference notes on them by a compilation of code examples, explanations and concepts. I used CPlusPlus.com, LearnCpp.com and DreamInCode.net 
I suggest you try the same approach.
Classes are actually very easy for me, it's just that I was never very good at data-structures so I suggest, if you are bad at structs then practice, practice, practice them until you become very good.
All the best.
You're not the only one who is/was weak in classes at first.
I suggest you try the same approach.
Classes are actually very easy for me, it's just that I was never very good at data-structures so I suggest, if you are bad at structs then practice, practice, practice them until you become very good.
All the best.
This post has been edited by hulla: 05 September 2011 - 07:50 AM
#3
Re: Classes Tutorial
Posted 05 September 2011 - 07:40 AM
Have you looked at the two Class links from this page: C++ Language Tutorial. If you did what don't you understand?
Jim
Jim
#4
Re: Classes Tutorial
Posted 05 September 2011 - 08:49 AM
Anyone know of a good structs tutorial, any help will be appreciated
#5
Re: Classes Tutorial
Posted 05 September 2011 - 08:52 AM
Have you checked out the DIC Tutorials yet?
#6
Re: Classes Tutorial
Posted 05 September 2011 - 08:56 AM
I will give you 2 min tutorial.
Unlike arrays, structs can contain different types, e.g.
You can initialize them like arrays!:
You can get the stuff out!:
If you pass the pointer to the struct, you CANT use dot operator!:
You could use the dot operator in the above example but then you would have to do:
Good luck.
Unlike arrays, structs can contain different types, e.g.
struct person
{
string name;
int age;
}; //note the semi colon!!!
You can initialize them like arrays!:
person a = {"bob the builder",12};
You can get the stuff out!:
void printPerson(person p)
{
std::cout << p.name << std::endl;
std::cout << p.age << std::endl;
}
If you pass the pointer to the struct, you CANT use dot operator!:
void printPerson2(person* p)
{
std::cout << p->name << std::endl;
std::cout << p->age << std::endl;
}
You could use the dot operator in the above example but then you would have to do:
void printPerson3(person* p)
{
std::cout << (*p).name << std::endl;
std::cout << (*p).age << std::endl;
}
Good luck.
#7
Re: Classes Tutorial
Posted 05 September 2011 - 08:57 AM
thanks it makes more sense now
#8
Re: Classes Tutorial
Posted 05 September 2011 - 08:59 AM
I've gone ahead and merged your two threads requesting tutorials since the answers in your first one are relevant for both topics.
#9
Re: Classes Tutorial
Posted 05 September 2011 - 09:00 AM
thanks, at least there are still cool people in this world
#10
Re: Classes Tutorial
Posted 05 September 2011 - 10:39 AM
Hadean Fall, on 05 September 2011 - 04:49 PM, said:
Anyone know of a good structs tutorial, any help will be appreciated
This is essentially a repeat of your original question - structs and classes are identical in C++. The only difference is their default access-specifier for members (If you don't know what that is yet, then you will after reading one of the tutorials on classes). In other words, there's absolutely nothing which a class can do which cannot also be done in exactly the same way using a struct.
#11
Re: Classes Tutorial
Posted 05 September 2011 - 10:39 PM
You forgot about the fact that a class can contain functions. Structs cannot contain functions.
#12
Re: Classes Tutorial
Posted 06 September 2011 - 03:47 AM
Yes they can. They cannot in C (where classes do not exist), but they can in C++.
You're thinking of C#.
In this language, structs are very different to classes (though they exist side by side). In C#, all classes are created on the heap (think Foo foo = new Foo();) whereas structs are created on the stack, and also cannot contain functions (think Foo foo;[il]).
However, in C++ [il]struct Foo { is exactly identical in all ways to:
You're thinking of C#.
In this language, structs are very different to classes (though they exist side by side). In C#, all classes are created on the heap (think Foo foo = new Foo();) whereas structs are created on the stack, and also cannot contain functions (think Foo foo;[il]).
However, in C++ [il]struct Foo { is exactly identical in all ways to:
class Foo {
public:
Note that is considered bad style to use structs for objects designed to have many functions. A struct is usually preferred if you have no or very few functions. Constructors and operators are also often included in structs.
This post has been edited by PlasticineGuy: 06 September 2011 - 03:48 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|