you don't need to include every header file in every file. for example, in People.cpp you included People.h WHICH ALREADY INCLUDES Birthday.h. so its redundant to include Birthday.h in People.cpp.
@@Astrax654 it`s because u have used the include guard in your files this include guard prevents the header from being included several times in the same file note : many compilers insert this include guard automatically in the same moment of file creation
This is not a composition but it is aggregation because birthday can live without people. In order to be composition, birthday object have to be created inside people and not in main
Yeah, more people should see it. Aggregation, association and composition are kinda similar but different things. I think because this is beginner series, Bucky just simplified it down to one term Composition without getting too much into details as it's already pretty confusing for beginners.
This is the first time I see one of your tutorials.The way you make something so scary-sounding like "programming" and the many fancy words like "Composition" etc. become so easy and simple to understand and learn to a beginner,is what takes to be a good teacher.And you've really mastered it - congratulations to you. :) *Subscribe,fav,like*
Bucky, your series ROCK ! A great fan of yours! One suggestion to this episode if I may: (min.6:45) EMPHASIZE the importance having line-12 and line-13 separated, instead of putting line-13 in the line-12 cout (a very intuitive looking, but a great way to spend a while TROUBLESHOOTING :) . RATIONALE - the func in line-13 returns nothing (void) - it by itself prints on the screen. If you put it in line 12, because the cout expects every function to return sth to work, and this function doesn't return anything - this leads to ERROR
To all of you people that DONT understand C++ but REALLY want to learn it: - Watch through all the tutorial videos from Bucky just to get a fast intro into the world of C++. DONT expect to learn anything from it. You cant learn C++ from watching a bunch of 5 minute videos, but you CAN get a fast intro to words and stuff you might recognize later. - (optional) Download Unreal Engine and learn to use the Blueprint system. This is fun as hell if you like amazing graphics, and will give you a great intro to coding i C++ (Unreal Engine is based on C++, and with blueprints you do it visually). Its free to download and in my opinion probably the strongest piece of software ever created. If you want to make games, you dont need to learn C++, you only need to learn Unreal Engine. - Do the CS50 course by Harvard! It is an introductory course to coding in C by Harvard. It is hard. Coding is hard. This is the least hard intro you can get IF you take your time and buy a complementary book to go along with the CS50 course. C++ is almost the same as C, only harder. So START with C, THEN go over to C++. - After doing the CS50, you are probably so good you can buy any "learn to code in C++" with a focus on what you really want to code (like "learn to code iphone apps in C++", or "learn to make games in C++").
Hello. In my country the school system in most of the highschools separate students in 2 "types of classes", one is for math,IT,physics,biology,chemistry, and one is for mothertongue,foreign languages,history,geography,philosophy,etc. Well i chose the easiest one which you can probably guess.Biggest mistake of my life. Well i was only 15... thats the sad part. They make us chose what are we going to do with our life at such an early age. 3 years had passed so far since then and now i want to study IT and get to an IT college which requires an entrace exam(c++). As I wasted my 3 years of highschool doing nothing now it's way too hard for me to learn such things as a programming language and especially learn it so i can beat other stdents at that college entrace exam. So far i got to this video from the tutorial.I lost it about 10 tutorials ago, but i hope after i finish the entire tutorial and i repeat it 2-3 times, ill be good-ish at C++. Btw, i dont think i'll ever get enough of that "pretty cool, huh?"
These tutorials are very hard for me to understand. I have no experience with coding and I'm practically just copycatting all the code written, that said I really appreciate that Bucky's recapping everything after each session. Though what would make it much simpler for, so that I can understand is a picture showing each coding element with arrows pointing at the interaction of the coding element. Also an explanation why the coding element needs to interact with the specific file etc. would help. It's hard for me to understand by just watching text and listening because often I need a logical explanation and in beginner level tutorials people tend to teach without telling the entire truth behind certain things. For instance why this and why that. Great videos tho, will complete several of them.
Questions: Have you worked from the beginning of these tutorials? And, are you stopping to make sure you understand everything he's written after each tutorial? I started coding 5 days ago and using Bucky's tutorials for 3 and this all makes perfect sense to me.
Good flippin' lord! This was the most confusing program to code for me that by the time I got it right it felt like I just won a freakin' Nobel Prize! Woop!
Should have my instructor, he is all over the place compared to this guy. At least he is specifically showing this in simple form and not crap like you would see with hardware. I learned more in the first 4 minutes of the last video than in the hour my iConnect did.
Here may be the reason for people's problems with header files. 1) Be absolutely sure that you have the #ifndef (token), #define (token) and #endif in every header file. This makes sure that if the file is included more than once, the preprocessor will erase it, effectively, only including it once. 2) Avoid including the same things in a cpp and the header file, only put it in the header. step 1 takes care of this but its still good practice to do so. Hope this solves some people's problems.
this topic seems to be comfusing to many - Its all about the relationship. Inheritance ('Is A' relationship:: A Dog is an Animal) Composition ( Has A, relationship :: A Person Has A Birthday) Inheritance - - inherit the good, bad & ugly, composition include objects of other classes into your container class.
Remember, birthdate is created outside of the constructor, therefore this video is about aggregation than composition since in composition contained object is created with the host object, where host object has total control over the contained object.
initializes the local variable name to the one provided and passes the object to the one from birthday, so after this, name is equal to the string provided and the birthday object has its info finally through the people class, so now print info function from the people class will cout the name and call the function print date with this object accesed from here throughh birthday. so printinfo does the whole final thing :)
Ohhhh so Jueecy was saying that Bucky was passing the object by value okay. Thanks for clarifying it. This is good to know the dos and donts as a newbie.
One thing has me confused here, I do not understand why the Birthday and the People constructors were initialized differently. nothing was declared as a constant.
@@beyondhelp I tried it just now, and I think that's partly right. I got errors when trying to initialise members of the people class non explicitly. Otherwise, yeah I think it is just preference.
wow men fantastic rlly thx , i come from java composed class , switch to c++ composed class all the examples that i found was in the same main.cpp and the assholes of stackoverflow start to dicking around , i finally managed to understand thanks to you =)
i had a difficult time understading composition but what i think of it as a egg and cheese bagel. If egg is considered to a class and its covered with cheese as another class, then drawing the final output in int main() will be easier
For those people who took the short cut and put all the classes into a single source file, you have to declare the Birthday class before the People class. If the People class comes first the compiler won't know how to use the Birthday class inside of it because it hasn't encountered it yet. This is the problem I ran into.
hey Bucky!! i love ur tutorials... i love ur teachin styles :P by d way m havin a little doubt... why didnt we use member initializers in birthday class for assigning date,month,year??? :/
@Olemassacre in the .h file you have all your functions. In cpp you have your functions coded. You include stuff in .h when you need it, like strings. You do not need to include namespace std because you do not use cin or cout there. You use them in the .cpp file. or that's how I got it. lol
Ít's because if you ever become good enough at programming to do it in a professional setting you'll work in a team making these things all on your own. It's also so that you can hide your code if you're sharing it with other people. It's also just good design practice!
Why in the Birthday class, did they pass the parameters into the body of the birthday constructor, but for the People class, the parameters were passed in using the : name(x), dataOfBirth(bo) approach?
check to make sure you named the actual printInfo function and declaration the same as the call to it(caps, underscores, etc). i know one of my most common mistakes is the caps and uncaps when naming and calling. printInfo isnt the same as PrintInfo
Can someone please tell me why did he do this member initializing in People constructor, but did not do it in Birthday constructor, he entered the {} and wrote inside them normally month = m etc. Thank you!!
I usually do Bucky's C++ tutorials on Visual Studio. I did everything precisely as he did, but received an error. However, I was able to solve it by adding the "#include " header to the People.cpp.
Why didn't he use a member initializer list here, for when he assigned values in the constructor for the Birthday class? Could someone please explain in what cases you are to use a member initializer list and when you should just assign the values in the function body instead? Or will either method work all the time?
My understanding is, and I use it in my constructor of my class, if you use the initializer list at the very instant the object is created it is set to the values. On the other hand, if you set the values inside the curly braces, it gets set after the object is created. For me, not much difference but i am sure there are some out there that can correct me if I am wrong, and maybe explain why you would need one over the other.
So, in main, you first create the birthObj with some parameters to set the variables for the birthObj class -> day, month, year. Then, when creating the People Object and calling the constructor function, you pass this object, since you will want to use this object in the people class, as parameter. You're just giving the People class access to the Birthday class by passing this object, since in the people class, you then use the Birthday.printBirthday() function. I can't write more.
i had a object as a member variable and i didn't need to use member initializer. i would like more clarification on why some times ya declare variables in the header and some times ya do it in the source file.
In A Nutshell: A class was created called birthday, on its header under public it has a birthday function/constructor which intakes the date, below is the print date, and under private the variables not yet associated, on the birthday cpp the constructor sets the variables to the input date, then passes it to a function from the birthday class and couts them, cool. thats a complete object now people takes in the string for the name and the object including its functions and people constructor
What I don't understand now is WHY use a different object name (bo) in the People constructor when it's going to be used the same birthObj created in main to access the Birthday class? WHY? I'm getting more and more confused each time ...... Is anybody around? !
It took me a while to get my head around this but I think I got there in the end! I tried working through this example in CodeBlocks, I kept getting an error in my People.h saying that my string did not have a name type. After checking a few forums I found that I had to change my "string" declarations in the body of People.h to "std::string". Does anybody know why? Perhaps I changed some default settings.
@Chriscs7 oh i realised what the problem was. You have to include all the #ifndef #endif nonsense, so it should look identical to what Bucky's got. I think he said in another tutorial its not important but it actually is!
Since those were private varibles. If you put that in another class, or even another part of that class, it would have no idea what month,day or year was.
+VeldroN your dads stupid then, go to code academy.com and learn every language on there before you learn c++. Unless you understand the fundamentals of programming you will never understand c++.
@Cezarijus Actually, there is a way. All you need to do, is pack all the headers into one header called "Library.h" for example and include that into every file. Then, if you need to change the name of something, just change it in the Library header, not in each and every file. It is the easiest way :) Very efficient. This can be used for all kinds of libraries, global variables, namespaces and so on.
Care to explain what's the benefits of passing objects-names to empty-object member I don't see the benefits of doing it since you already have access it through header file
Hello awesome tut! But 2 questions. First, if i dont want to pit #include in people.h becsuse reason.. how do i do it the other way? Second, so with this way of doing things i can now stop using innherance? Lol (not serious..)
@Friedtunafish77 wouldn't that make you iinclude headers that you don't necessarily need? or it doesn't matter if you include a header file and don't use it?
I keep getting this error. Any ideas as to why? mingw32-g++.exe: error: programs\youTube\Birthday.cpp -o obj\Debug\Birthday.o: No such file or directory Process terminated with status 1 (0 minute(s), 0 second(s))
He is saying that you should pass objects, not functions from another class, to a function/method either by reference or const reference for efficiency.
meant to ask this before: what is the difference between member initializer (the double colons thing before the body) and actually initialzing the values in the constructor? In this example: why write birthday::birthday(int d, int m, int y) { day = d; month = m; year = y; } instead of birthday::birthday(int d, int m, int y) :day(d), month(m), year(y){ } in the birthday class? like he did in the people class? from previous videos i know that if the attribute is a const, then you need the member initialzer, but if it's a regular variable, what is the difference? both ran with no error and same output btw.
+zzZMrWangZzz using the member initializer is more efficient since it does two operations in 1: declares the variable (allocate memory for it) and initialize it with a value AT THE SAME TIME. unlike when not using it, memory is allocated for the member variables first then LATER initialize it in the constructor body. the efficiency is better seen when initializing data members THAT ARE OBJECTS which inside them contain their own set of data members. when not using member initializer with objects, the objects default constructor wiill be called first and assign it with default values THEN LATER ASSIGN IT WITH the values you intend for it to have. ITS MUCH MORE EFFICIENT TO ASSIGN IT WITH THE DESIRED VALUES DURING ITS CONSTRUCTION AND NOT START WITH SOME DEFAULT VALUES.
Compostition is best left untouched , I try to use it the least amount of times I can and try not to mingle my classes unless there is absolutely no other way.
Why isn't it necessary for the int's month, day and year to be initialized before the "Birthday(int m, int d, int y);" Is private or public ran first, at the same time?
Is there a difference between doing: Person(string name, int age) { this->name = name; this->age = age; } Person(string name, int age): age(age), name(name) { }
+targetghig nojhfgujfgj Really? I saw it as useful for team development but I always saw it easier to organize while in the same file as you have everything there you won't miss a class you can't see because you've opened tons of classes. Matter of preference I suppose.
pretty cool huh x 3 XD
you don't need to include every header file in every file. for example, in People.cpp you included People.h WHICH ALREADY INCLUDES Birthday.h. so its redundant to include Birthday.h in People.cpp.
is this why you don't need to add the " #include " to " People.cpp " ?
@@Astrax654
it`s because u have used the include guard in your files
this include guard prevents the header from being included several times in the same file
note :
many compilers insert this include guard automatically in the same moment of file creation
@@Astrax654 same here
This is not a composition but it is aggregation because birthday can live without people. In order to be composition, birthday object have to be created inside people and not in main
Yeah, more people should see it. Aggregation, association and composition are kinda similar but different things. I think because this is beginner series, Bucky just simplified it down to one term Composition without getting too much into details as it's already pretty confusing for beginners.
i've been about 4 hours triying to realise what to do with my c++ project and you just save me the life. Cheers
pretty cool huh ! -- bucky favourite expression :P
*come on dude, 30 videos left, you can do this!*
thanks ...i needed this
I swear my brain grew like 10% after this tutorial.
Even after five years, this video just gave me a better understanding of composition. Thank you lots
This is the first time I see one of your tutorials.The way you make something so scary-sounding like "programming" and the many fancy words like "Composition" etc. become so easy and simple to understand and learn to a beginner,is what takes to be a good teacher.And you've really mastered it - congratulations to you. :)
*Subscribe,fav,like*
Pretty kool haan
Bucky, your series ROCK ! A great fan of yours!
One suggestion to this episode if I may: (min.6:45)
EMPHASIZE the importance having line-12 and line-13 separated, instead of putting line-13 in the line-12 cout (a very intuitive looking, but a great way to spend a while TROUBLESHOOTING :) .
RATIONALE - the func in line-13 returns nothing (void) - it by itself prints on the screen. If you put it in line 12, because the cout expects every function to return sth to work, and this function doesn't return anything - this leads to ERROR
It was obvious I think
The best explanation of the notion of "Composition"
Thanks Bucky, and it is indeed "pretty cool, huh" XD ;)
man i dont know what the f i would have done without your amaizng content!
After watching again I now understand.
To all of you people that DONT understand C++ but REALLY want to learn it:
- Watch through all the tutorial videos from Bucky just to get a fast intro into the world of C++. DONT expect to learn anything from it. You cant learn C++ from watching a bunch of 5 minute videos, but you CAN get a fast intro to words and stuff you might recognize later.
- (optional) Download Unreal Engine and learn to use the Blueprint system. This is fun as hell if you like amazing graphics, and will give you a great intro to coding i C++ (Unreal Engine is based on C++, and with blueprints you do it visually). Its free to download and in my opinion probably the strongest piece of software ever created. If you want to make games, you dont need to learn C++, you only need to learn Unreal Engine.
- Do the CS50 course by Harvard! It is an introductory course to coding in C by Harvard. It is hard. Coding is hard. This is the least hard intro you can get IF you take your time and buy a complementary book to go along with the CS50 course. C++ is almost the same as C, only harder. So START with C, THEN go over to C++.
- After doing the CS50, you are probably so good you can buy any "learn to code in C++" with a focus on what you really want to code (like "learn to code iphone apps in C++", or "learn to make games in C++").
void buckycool()
{
cout
pretty cool hun!!!
Hello. In my country the school system in most of the highschools separate students in 2 "types of classes", one is for math,IT,physics,biology,chemistry, and one is for mothertongue,foreign languages,history,geography,philosophy,etc.
Well i chose the easiest one which you can probably guess.Biggest mistake of my life. Well i was only 15... thats the sad part. They make us chose what are we going to do with our life at such an early age. 3 years had passed so far since then and now i want to study IT and get to an IT college which requires an entrace exam(c++). As I wasted my 3 years of highschool doing nothing now it's way too hard for me to learn such things as a programming language and especially learn it so i can beat other stdents at that college entrace exam.
So far i got to this video from the tutorial.I lost it about 10 tutorials ago, but i hope after i finish the entire tutorial and i repeat it 2-3 times, ill be good-ish at C++.
Btw, i dont think i'll ever get enough of that "pretty cool, huh?"
These tutorials are very hard for me to understand. I have no experience with coding and I'm practically just copycatting all the code written, that said I really appreciate that Bucky's recapping everything after each session.
Though what would make it much simpler for, so that I can understand is a picture showing each coding element with arrows pointing at the interaction of the coding element. Also an explanation why the coding element needs to interact with the specific file etc. would help.
It's hard for me to understand by just watching text and listening because often I need a logical explanation and in beginner level tutorials people tend to teach without telling the entire truth behind certain things. For instance why this and why that.
Great videos tho, will complete several of them.
Questions: Have you worked from the beginning of these tutorials? And, are you stopping to make sure you understand everything he's written after each tutorial? I started coding 5 days ago and using Bucky's tutorials for 3 and this all makes perfect sense to me.
Good flippin' lord! This was the most confusing program to code for me that by the time I got it right it felt like I just won a freakin' Nobel Prize! Woop!
Should have my instructor, he is all over the place compared to this guy. At least he is specifically showing this in simple form and not crap like you would see with hardware. I learned more in the first 4 minutes of the last video than in the hour my iConnect did.
Happy Birthday Bucky the king!
Here may be the reason for people's problems with header files.
1) Be absolutely sure that you have the #ifndef (token), #define (token) and #endif in every header file. This makes sure that if the file is included more than once, the preprocessor will erase it, effectively, only including it once.
2) Avoid including the same things in a cpp and the header file, only put it in the header. step 1 takes care of this but its still good practice to do so.
Hope this solves some people's problems.
"You're saying: alright." (Times infinity)
-Bucky Roberts
this topic seems to be comfusing to many - Its all about the relationship. Inheritance ('Is A' relationship:: A Dog is an Animal) Composition ( Has A, relationship :: A Person Has A Birthday) Inheritance - - inherit the good, bad & ugly, composition include objects of other classes into your container class.
I knew my problem will get solved after watching Bucky's tutorial
@thenewboston Happy Birthday, i happen to be watching this today :-)
Remember, birthdate is created outside of the constructor, therefore this video is about aggregation than composition since in composition contained object is created with the host object, where host object has total control over the contained object.
I like your videos because of it's simplicity and buecause you speak an english that I easily can understand (i'm frim Spain). So, thank you!
from 1:57 to 6:45 I was yelling at you in my head that you were forgetting to include the parameters in the constructor
Same'
WOOOW you've explained about composition in a nutshell. Thanks for this tutorial :)
initializes the local variable name to the one provided and passes the object to the one from birthday, so after this, name is equal to the string provided and the birthday object has its info finally through the people class, so now print info function from the people class will cout the name and call the function print date with this object accesed from here throughh birthday. so printinfo does the whole final thing :)
Ohhhh so Jueecy was saying that Bucky was passing the object by value okay. Thanks for clarifying it. This is good to know the dos and donts as a newbie.
Happened to watch this tutorial on your birthday, happy birthday thanks for your work :)
isn't using namespace std; in the header file flooding the main.cpp and better to use std:: before the string types?
Awesome! Keep it up! Thanks from Kazakhstan!
One thing has me confused here, I do not understand why the Birthday and the People constructors were initialized differently. nothing was declared as a constant.
In People constructor,u use an object of another class in the program unlike Birthday constructor.
Steve Hedemann its really just optional, it doesn't matter if you initialize in the body, or use the member initailizer, he's just showing both
@@beyondhelp I tried it just now, and I think that's partly right. I got errors when trying to initialise members of the people class non explicitly. Otherwise, yeah I think it is just preference.
Live long the king Bucky
Those two video's really helped me alot! Thumbs up, thank you man! You're great :)
Don't we need to include string class in the people.cpp??
wow men fantastic rlly thx , i come from java composed class , switch to c++ composed class all the examples that i found was in the same main.cpp and the assholes of stackoverflow start to dicking around , i finally managed to understand thanks to you =)
How do you know when to use the member initialization list or to put it in the body of the constructor
i had a difficult time understading composition but what i think of it as a egg and cheese bagel. If egg is considered to a class and its covered with cheese as another class, then drawing the final output in int main() will be easier
guys, i keep getting errors, wtf
For those people who took the short cut and put all the classes into a single source file, you have to declare the Birthday class before the People class. If the People class comes first the compiler won't know how to use the Birthday class inside of it because it hasn't encountered it yet. This is the problem I ran into.
hey Bucky!! i love ur tutorials...
i love ur teachin styles :P
by d way m havin a little doubt...
why didnt we use member initializers in birthday class for assigning date,month,year??? :/
Because we do not initialize an object of other class, only three ints, month, day, year.
You could have, but whenever you use the initializer list all objects created are initialzed with that same value.
i was totally skeptical until this point that if i code anything but calculations and stuff but when u add creativity u can do anything
Thank you so much Bucky I missed out on two points because I couldn't do this!
@Olemassacre in the .h file you have all your functions. In cpp you have your functions coded. You include stuff in .h when you need it, like strings. You do not need to include namespace std because you do not use cin or cout there. You use them in the .cpp file. or that's how I got it. lol
Ít's because if you ever become good enough at programming to do it in a professional setting you'll work in a team making these things all on your own. It's also so that you can hide your code if you're sharing it with other people. It's also just good design practice!
How funny, Bucky, we share a birthday. 3 days after Christmas always getting shorted when it comes to gifts haha
Why in the Birthday class, did they pass the parameters into the body of the birthday constructor, but for the People class, the parameters were passed in using the : name(x), dataOfBirth(bo) approach?
Every 2 seconds: Pretty cool, huh?
check to make sure you named the actual printInfo function and declaration the same as the call to it(caps, underscores, etc). i know one of my most common mistakes is the caps and uncaps when naming and calling. printInfo isnt the same as PrintInfo
Can someone please tell me why did he do this member initializing in People constructor, but did not do it in Birthday constructor, he entered the {} and wrote inside them normally month = m etc. Thank you!!
either way it works... but I also have the same question.
Because it's people who have birthday rather then the birthday has people.
I'm watching your video on "28/12/2017"
Happy Birthday !!!
for some reason codeblocks won't build the main.cpp file.
after restarting it worked, miracles do happen!
Mike M This.. Fucking codeblocks error undefined reference to WinMain16.
+Ticomfreak Codeblocks master race! If you don't screw it up
+TeleTubbie Luver No, Eclipse master race!
If you setup CDT correctly, then you can edit java and c++ files all together in one IDE
I usually do Bucky's C++ tutorials on Visual Studio. I did everything precisely as he did, but received an error. However, I was able to solve it by adding the "#include " header to the People.cpp.
Wow! Way better than my Lecturer
Why didn't he use a member initializer list here, for when he assigned values in the constructor for the Birthday class?
Could someone please explain in what cases you are to use a member initializer list and when you should just assign the values in the function body instead? Or will either method work all the time?
My understanding is, and I use it in my constructor of my class, if you use the initializer list at the very instant the object is created it is set to the values. On the other hand, if you set the values inside the curly braces, it gets set after the object is created. For me, not much difference but i am sure there are some out there that can correct me if I am wrong, and maybe explain why you would need one over the other.
So, in main, you first create the birthObj with some parameters to set the variables for the birthObj class -> day, month, year. Then, when creating the People Object and calling the constructor function, you pass this object, since you will want to use this object in the people class, as parameter. You're just giving the People class access to the Birthday class by passing this object, since in the people class, you then use the Birthday.printBirthday() function. I can't write more.
i had a object as a member variable and i didn't need to use member initializer.
i would like more clarification on why some times ya declare variables in the header and some times ya do it in the source file.
I wanna cry.We can do easly without class files.But I believe you these informations will work in the future.
In A Nutshell: A class was created called birthday, on its header under public it has a birthday function/constructor which intakes the date, below is the print date, and under private the variables not yet associated, on the birthday cpp the constructor sets the variables to the input date, then passes it to a function from the birthday class and couts them, cool. thats a complete object now people takes in the string for the name and the object including its functions and people constructor
This video was PRETTY COOL HUH?
huh???
Bucky IS the king
Where is Bucky??? It's been 7 months since a video!
What I don't understand now is WHY use a different object name (bo) in the People constructor when it's going to be used the same birthObj created in main to access the Birthday class? WHY? I'm getting more and more confused each time ...... Is anybody around? !
@Peterolen Thank you 👍🏿
Grab a milkshake? I'll grab oranges instead XD
Your videos are so Good, Thank You So Much.
It took me a while to get my head around this but I think I got there in the end! I tried working through this example in CodeBlocks, I kept getting an error in my People.h saying that my string did not have a name type.
After checking a few forums I found that I had to change my "string" declarations in the body of People.h to "std::string". Does anybody know why? Perhaps I changed some default settings.
"When ever your working with an object, you need to 'inclu-l-l-l' it"
hard to keep up, but hey, hard means provocative! good luck and practice using codeblocks, split your screen, left: codeblock, right: youtube
@Chriscs7 oh i realised what the problem was. You have to include all the #ifndef #endif nonsense, so it should look identical to what Bucky's got. I think he said in another tutorial its not important but it actually is!
Holy crap I actually got it to work after fixing only 5 errors!!!! Yes!!!!!!!!!!
I am ready for the next tutorial, even without a milkshake hhhh :p
Happy Birthday!!!
hello, thx for this tutorial, its great. but the topic is pretty hard. i definitely need more examples @composition. so what would you suggest me??
You don't need to include birthday.h and namespace std in People.cpp. They are already included in header file....there's redundant calls.
make sure you are properly assigning it data. read through your code make sure the variable names are passed correctly.
Since those were private varibles. If you put that in another class, or even another part of that class, it would have no idea what month,day or year was.
This is soooo hard :((
So much stuff in so many different files is confusing :(
Aaaand,i've come to the conclusion that i'm an idiot
Ty
Yeah well,i started to learn C++ as my first programming language just because that's what my dad wanted :P
+VeldroN your dads stupid then, go to code academy.com and learn every language on there before you learn c++. Unless you understand the fundamentals of programming you will never understand c++.
you should of started with a beginners language like pascal
De Shad Bostic nahhhhh pascal is garbage. java is a terrible start too. python is probably the best language to start by far.
@Cezarijus Actually, there is a way. All you need to do, is pack all the headers into one header called "Library.h" for example and include that into every file. Then, if you need to change the name of something, just change it in the Library header, not in each and every file. It is the easiest way :) Very efficient. This can be used for all kinds of libraries, global variables, namespaces and so on.
this->x is the same thing as (*this).x, it's just a convenient shortcut
Thanks king!! This is actually PRETTY COOL! hhaha
Care to explain what's the benefits of passing objects-names to empty-object member
I don't see the benefits of doing it since you already have access it through header file
Hello awesome tut! But 2 questions.
First, if i dont want to pit #include in people.h becsuse reason.. how do i do it the other way?
Second, so with this way of doing things i can now stop using innherance? Lol (not serious..)
very helpful bro, thanks for the explanation : )
I wonder why he uses the constructor differntly for birthday and for people.
@Friedtunafish77 wouldn't that make you iinclude headers that you don't necessarily need? or it doesn't matter if you include a header file and don't use it?
I keep getting this error. Any ideas as to why?
mingw32-g++.exe: error: programs\youTube\Birthday.cpp -o obj\Debug\Birthday.o: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
He is saying that you should pass objects, not functions from another class, to a function/method either by reference or const reference for efficiency.
meant to ask this before: what is the difference between member initializer (the double colons thing before the body) and actually initialzing the values in the constructor? In this example: why write
birthday::birthday(int d, int m, int y)
{
day = d;
month = m;
year = y;
}
instead of
birthday::birthday(int d, int m, int y)
:day(d), month(m), year(y){
}
in the birthday class? like he did in the people class? from previous videos i know that if the attribute is a const, then you need the member initialzer, but if it's a regular variable, what is the difference?
both ran with no error and same output btw.
+zzZMrWangZzz using the member initializer is more efficient since it does two operations in 1: declares the variable (allocate memory for it) and initialize it with a value AT THE SAME TIME. unlike when not using it, memory is allocated for the member variables first then LATER initialize it in the constructor body.
the efficiency is better seen when initializing data members THAT ARE OBJECTS which inside them contain their own set of data members. when not using member initializer with objects, the objects default constructor wiill be called first and assign it with default values THEN LATER ASSIGN IT WITH the values you intend for it to have. ITS MUCH MORE EFFICIENT TO ASSIGN IT WITH THE DESIRED VALUES DURING ITS CONSTRUCTION AND NOT START WITH SOME DEFAULT VALUES.
That's where you have to put the "syntax variables", it's just how the developers of c++ made it.
Compostition is best left untouched , I try to use it the least amount of times I can and try not to mingle my classes unless there is absolutely no other way.
Found the person who makes spaghetti code trough Inheritance... :P
I dont understand when you use the weird member initializer syntax and when you dont
this got me spinning after halfway.
@thenewboston dang your birthday was 2 days ago.... I knew I should have watched this tutorial earlier
Why isn't it necessary for the int's month, day and year to be initialized before the "Birthday(int m, int d, int y);" Is private or public ran first, at the same time?
I got tripped up for a second because i tried to put dateOfBirth.printDate(); on the same line as cout
Is there a difference between doing:
Person(string name, int age) {
this->name = name;
this->age = age;
}
Person(string name, int age):
age(age),
name(name)
{
}
We should really place it into one file... Like im tired of placing 5 classes in 5 diffrent classes. We didnt reach that level yet.
It's good practice.
you can do what you think is easy for you but separating classes can help avoid confusion in a bigger project
+targetghig nojhfgujfgj Really? I saw it as useful for team development but I always saw it easier to organize while in the same file as you have everything there you won't miss a class you can't see because you've opened tons of classes. Matter of preference I suppose.