Hey dwks,
Thanks for the quick reply and also for your suggestion, you're right, my code isn't the cleanest in the slightest, and using a switch would make a lot more sense for a menu. :)
...
Type: Posts; User: kbro3
Hey dwks,
Thanks for the quick reply and also for your suggestion, you're right, my code isn't the cleanest in the slightest, and using a switch would make a lot more sense for a menu. :)
...
Hi guys, a bit of a lengthy post, but bear with me please:
I've had a small problem in my program where I declared functions for a simple menu.
There are several menus that are embedded - that...
Ah thanks for that, did not realise the member objects are created automatically, but I tried it and as you said, it works.
I'm very new to C++ and have not yet played with an initialisation...
Thanks, I created a getter in Orc, called getWeaponDescription, this is what I wrote:
string Orc::getWeaponDescription()
{
return weapon1.getDescription();
Ah crap, yes I see what you mean. getDescription is a public function of Weapon object. But I listed Weapon object as a private attribute of Orc, so i would not be able to call its' public methods...
Yes, I do want to default construct the Weapon object. Don't I need to call the constructor? (that's what I tried to do in the code). Are you saying that a default weapon object would be created...
Hi guys,
Just having a small problem with something i'm playing around with.
Basically, I have two classes, an Orc class that creates Orc objects, and a Weapon class that creates Weapon...
Ah yes, got it. So there are no, or at least minimal performance overheads in having several includes?
Thanks for taking the time to explain the logic behind the code, that's what I was after! :)
Sorry to bring this up again, just wanted to get everything working the right way, not interested in bad code to make things work.
I checked command line options, and found how to "link" the...
Ah great, yes I thought that it was strange to include the .cpp instead of .h, seeing as one of the points of header files is to "hide" the implementation of classes while allowing their use.
And of...
Okay, so instead of using namespace std, I should use std:string for string types? Also, to avoid including the person.cpp in my driver, I compile person.cpp, then compile the driver, then somehow...
Okay, got everything to work,
Turns out I needed to #include <string> in Person.h and also do using namespace std in Person.h
I then compiled person.cpp (not to executable, but just compile and...
Ah cheers, so if I create a driver with a main function, and compile that, it will compile everything?
Or, should I use a different option in the compiler, so that it doesn't build an executable,...
Okay, i've included a string in my Person.h AND Person.cpp
(#include <string>)
I also removed the const and std::string, replaced with a using namespace std
in BOTH Person.h and Person.cpp
...
Ok, yeah I see I forgot to put the right parameters into the setAge() member function.
Here's a question, instead of qualifying string with std::string everywhere, as you mentioned I can use the...
Thanks for your help, unfortunately that doesn't compile either.
I now get:
error: expected `)' before 'name'
error: 'string' does not have a type
error: prototype for 'char Person::getSex()'...
Yeah sorry, should have included the error message:
'string' does not name a type
expected ')' before 'name'
In constructor 'Person::Person()' :
'name' was not declared in this scope
At...
Hi guys,
I'm very new to C++, although have some experience in Java.
Anyway, I'm currently learning about separating code through header files (for class declarations) and storing the...
I'm required by assignment guidelines to use char arrays... :(
-Kirill
This is strange.
Could the fact it's in separate files be the problem? But then again, it does see the function, and does return something.. just not the whole array.. i'm super confused. Btw, i'm...
Absolutely, what i quoted here is EXACTLY my code. It still doesn't work, now i've updated the getLastName() function, so now i'm getting returns of 0 for first name and nothing for last name!
:(...
Ah okay, i'll post up my whole project, because I haven't got that much code at the moment anyways:
This is game.cpp (the driver, and where everything will happen:)
#include <iostream>...
Okay, there are three files in my project, Player.h (Player class, where playerFirstName) Player.cpp (definitions of functions from Player.h) and maingame.cpp (main driver)
maingame.cpp call the...
Tried this, now i'm getting 0.. :(
char* Player::getFirstName()
{
return playerFirstName;
Hi guys,
Having a problem returning a whole char array from a function. (Player name)
For example, I have a player class, one of the attributes is char playerName[10].
I have a public...