02:32
Allo there
When working with the enum type in C++, is the point just so your string literals give meaningful names? because it doesnt operate like an array, meaning i cant do function method takes the int index of an enum and hten print the string
Right.
Well... enums provide type safety.
eg: enum BirthStones { Garnet = 1, Amethys, Aquamarine.... }
Unlike the old C style #define's, enum's are type safe.
02:33
then i have a method later on in the class, getBirthStones(int month) { // stuff goes here return BirthStone(month); }
(You can't pass an enum where an string is expected.)
Right.
int to enum is an invalid conversion.
so in order to have this work properly, i need to create an indexed array, that coinsides with the ENUM, and then print that?
...assuming that's what you're doing.
the criteria: Create an enumeration for the months in the year, add a function named getBirthstone that returns the birthstone based on the month.
Well... why can't getBirthStone() have the enum as its parameter?
02:35
i was trying do it in reverse, using an enum of the birthstones
so, if i pass in the enum as a parameter, i can call it by index?
let me gist my open buffers
You can convert an enum to an int if you need to.
I'll point out a few things as I come across them...
- First off, displayMenu() should probably return the value it gets from cin instead of putting it in a global variable.
Oh, I see what you're doing.
You're having the user input an integer, and you wan't it stored using the enum.
Well there's two things you can do...
- First, you could have a function in Person that has a switch that converts the int into the appropriate enum.
02:41
ok going to whip that up then
- Or you could simply use int's throughout and only use the enum for comparison.
(Which might be a better option.)
hmmm
i dont follow
What I mean is... continue to use int for storing the month...
right
...and then whenever you're comparing another value to the int, use the enum like so:
> if(month == GARNET)...
...or whatever. In that case, the only purpose of the enum is to keep you from hardcoding integer values for the items.
(Since that's exactly what we're trying to avoid.)
02:45
ok hang on let me try this and see if i'm following. right now i'm trying to figure out what i've done wrong in my switch in birthdayInfo
its stopped compiling with an issues about crosses initialization of std::string inputName
Can I see what you have?
*i changed the variable name from name, to inputName on line 41
Hmm... another problem...
also this isnt going to work the way i have it, with displayMenu() as the criteria
it will run twice
i just noticed that
Right.
I was about to say that.
You need to store the value somewhere.
... or use a do...while() loop.
...which is probably a better idea.
That way the menu will always be display once.
So you have:
> do {
02:48
DO { // stuff } while (DisplayMenu() != -1)
Right, except you should store the value you get from displayMenu().
Can I stick this in a pastebin?
hmmm
sure
or you can fork it on gist :P
i use gist because i have a hook in vim to auto-post to it.
object heirarchy, does case1 cause myperson to fall out of scope?
No.
First of all, a case isn't a new scope.
02:56
tmp/cccttnc9.o: In function `main':
birthdayInfo.cpp:(.text+0x1dc): undefined reference to `Person::setName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
(This really surprises a lot of people.)
i didnt think so but C++ says its angry about it
Can I see what you have now?
Are you linking person.cpp?
That's the only thing I can think of that would cause that problem.
02:59
ugh right
the linux toolchains demand i do that
just including the prototype header wont do that automagically
Otherwise you have a reference to a function that doesn't exist in code :)
thats what i get for putting off this homework/project for two weeks, i forgot everything :|
When you compile main.cpp, you'll end up with main.o which contains the code for main.cpp.
I took this as an opportunity to learn the linux C/C++ toolchain vs using VS that school teaches
That code references Person::setName which is declared in person.h.
03:00
If i were to drop Vim, what IDE would you recommend for C++ development?
Qt Creator!
you said something about the QT ide not to long ago i beleive
ok let me apt-get it
Yup, it's the best - even for straight C++ (without using Qt at all).
wow
307 megs of libs
\o/
It's big.
03:01
i see
wonder how its going to perform on my netbook
Its performance is good.
I think all those files are related to the Qt dev. headers / libs.
No clue why Qt Creator needs those, though.
shrug i leave all that up to the maintainers. I gave up on pondering package dependencies a long time ago
if they say so, by all means i'll eat the space to house them
i hate building packages and then trying to fix it when i try to circumvent repositories dependencies. Slack taught me quite a bit about that.
I've learned to leave them alone too... ever since I force-installed a package on an Ubuntu install - and it corrupted the package DB so bad that I had to reinstall pretty much every package on the system.
oh dude this is sexy
grokks qtcreator
Let me know if you have any questions about using it.
The code-completion and indexing in Qt Creator is unparalleled.
03:11
so if i dont use a project, it wont let me build/debug?
Yeah.
...but that's common with most IDEs (at least on Linux).
bummer
Creating a project is pretty easy though.
going through the wizard now
For a straight C++ app, just choose "Qt Console" and delete everything it creates for you.
03:15
ah i chose C++ Shared Library anbd just removed the QT dependencies
@lazyPower Oh... that will create a .so binary.
i see
Dude i cant get over this interface
this is slick as hell
It's not bad.
A bit of searching has discovered that in order to remove Qt dependencies, you need to add this to your .pro file:
> CONFIG -= qt
...and that will create a generic run-of-the-mill C++ executable.
If you ever are interested in learning Qt, let me know.
Let me get the basics of C++ down and i'll consider it :)
right now i'm happy being a VB/C#/PHP developer, and C++ for school. I thought about picking up Python, but C++ may be the route i go instead for the short-term since I'll have a few months of schooling in it.
string Person::getBirthStone(int month)
{
switch (month)
case Garnet:
return "Garnet";
case Amethyst:
return "Amethyst";
case Aquamarine:
return "Aquamarine";
case Diamond:
return "Diamond";
}
was that along the lines of what you were getting at?
03:31
That would work.
shit the criteria was enum of months but thats a quick fix
@GeorgeEdison defining that enum, i should be able to pass it in as a parameter of the prototyped class method correct? string Person::getBirthStone(Months month) correct?
@lazyPower That function just returns a string for the month right?
negative, it returns a string of the birthstone
hang on i'll pastebin the files
Ah, I see.
Yup, that will work fine.
:|
says on line 40 of person.cp: /home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘std::string Person::getBirthStone’ is not a static member of ‘class Person’
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘Months’ was not declared in this scope
does not compute as to why its not valid in my brain
its declared as public in the class, and htis is the class body
so what scope is there that its not defined in?
03:45
Is it declared in Person.h?
Can I see Person.h?
in the public block
its on that last paste
Ah, I see it.
line 83 and below
03:47
For the months error, you need to change Months in the function to Person::Months, IIRC.
Since you've declared it inside the class, you need to use the class qualifier to access it.
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘std::string Person::getBirthStone’ is not a static member of ‘class Person’
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘Months’ is not a member of ‘Person’
>.>
makes me want to punch babies
Hang on. Lemme fire up Qt here...
Small note... Person:48 - you spelled February wrong :)
It compiles for me...
oh what the heck
03:50
...what's in main.cpp?
Yup. It all builds cleanly for me? What errors are you still getting?
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘std::string Person::getBirthStone’ is not a static member of ‘class Person’
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:40: error: ‘Months’ is not a member of ‘Person’
/home/charles/Dropbox/School/CeePlusPlus/BirthdayProfile-build-desktop/../BirthdayProfile/person.cpp:41: error: expected ‘,’ or ‘;’ before ‘{’ token
Are all of the files added to the project?
03:53
Just to make sure everything is synced, can you put all of the files somewhere again?
Just to make sure I have exactly what you have.
Aha! I reproduced them.
what i did?
haha
You've got two different functions for getBirthStone().
One takes an int - the other takes a Month.
They both need to be the same or the compiler thinks you're trying to declare a new function...
...which is not possible. Hence the error.
...and what happened to the Months enum?
I can't find it anymore.
err
its in there
this is odd
it made two directories
one of the project folder, the initial directory, now its gone one with a -build-desktop appended.
04:00
Actually...
Qt creates a second directory with the compiled files in it and sticks -build-desktop on the end to distinguish it.
wth
it IS missing
throws a fit
i must have been editing while debugging and it vaped my changes
Yeah and that method declaration in the prototype did have months as its param
visible in the pastebin
i made changes while the IDE was doing something and it didnt take any of my changes
how do i stop the IDE from sitting in limbo durin ga failed build so i dont have this issue again?
"sitting in limbo durin ga failed" - what do you mean?
it was sitting in limbo during the failed build. i saw the debug screen, and it did nothing. i made changes and apparently after cleaning the build it erased my source changes.
The debug screen? You mean the button under "Design" on the left?
the view in the center
04:11
Oh, right.
That's the debug view (as opposed to the edit view). Weird though - I can always edit files when it's debugging.
Does it compile now?
and it doesnt wipe changes?
yeah, trying to interface with it in the output screen. i've either got a logic error or its not reading my input.
rather, the application output screen
@lazyPower Oh, you mean the output window at the bottom?
Yeah, it's not interactive.
Yessir, tab 3
that makes sense :)
haha
You'll have to run it in a terminal.
04:32
Awesome
i think the growing pains are over
i understand what i was trying to do now that i've failed at it horibly four or five times and now i have a working, and compiling project thats doing what i tell it to
hi5 @GeorgeEdison, i owe you man.