Getting an error using my Constructor

Posts 1–15 of 20 · Page 1 of 2
Getting an error using my Constructor
Im getting this error
Code:
1>c:\users\patrick\documents\visual studio 2008\projects\more constructor practice\more constructor practice\main.cpp(4) : error C2533: 'pokemon::{ctor}' : constructors not allowed a return type
How is it thinking im trying to return something?

Classes.h:
[php]#include <iostream>
using namespace std;

class pokemon
{
public:
pokemon(int iAge, int iWeight, char iGender); //constructor and destructor
~pokemon();
int GetAge() { return cAge; } //accessor functions
void SetAge(int age) { cAge = age; }

int GetWeight() { return cWeight; }
void SetWeight(int weight) { cWeight = weight; }

int GetGender() { return cGender; }
void SetGender(char gender) { cGender = gender; }

void Retreat() { cout << "Retreated\n"; } //random function
private:
int cAge;
int cWeight;
char cGender;
}
[/php]

Main.cpp:
[php]#include "classes.h"

pokemon:okemon(int iAge, int iWeight, char iGender) //constructor of pokemon,
//Im getting the error here.
//Says im trying to return something
{
cAge = iAge;
cWeight = iWeight;
cGender = iGender;
}

pokemon::~pokemon() {} //destructor


int main()
{
pokemon Pikachu(5, 15, 'F');
cout << "Age:\t" << Pikachu.GetAge() << '\n';
cout << "Weight:\t" << Pikachu.GetWeight() << '\n';
cout << "Gender:\t" << Pikachu.GetGender() << '\n';
}


[/php]

//
constructors don't take arguments.
They're called when you create an object of that type.

Code:
pokemon::pokemon()
{
    //this code is called when you do 'pokemon *pPokemon = new pokemon'
}
But for some reason this works.

[php]bear::bear(int iAge, int iWeight)
{
cAge = iAge;
cWeight = iWeight;
}[/php]
the problem is on the class

fixed

Code:
#include <iostream>
using namespace std;

class pokemon
{
public:
    pokemon(int , int , char); //constructor and destructor
    ~pokemon();
    int GetAge() { return cAge; } //accessor functions
    void SetAge(int age) { cAge = age; }

    int GetWeight() { return cWeight; }
    void SetWeight(int weight) { cWeight = weight; }

    int GetGender() { return cGender; }
    void SetGender(char gender) { cGender = gender; }

    void Retreat() { cout << "Retreated\n"; } //random function
private:
    int cAge;
    int cWeight;
    char cGender;
};
you missed ; at the end of the class
Quote Originally Posted by 'Bruno View Post
the problem is on the class

fixed

Code:
#include <iostream>
using namespace std;

class pokemon
{
public:
    pokemon(int , int , char); //constructor and destructor
    ~pokemon();
    int GetAge() { return cAge; } //accessor functions
    void SetAge(int age) { cAge = age; }

    int GetWeight() { return cWeight; }
    void SetWeight(int weight) { cWeight = weight; }

    int GetGender() { return cGender; }
    void SetGender(char gender) { cGender = gender; }

    void Retreat() { cout << "Retreated\n"; } //random function
private:
    int cAge;
    int cWeight;
    char cGender;
};
you missed ; at the end of the class
Im gonna gtfo mpgh for a while
ima disgrace to myself.
Constructors can take arguments if you want them to. |:
Ok. Im retarded. im gonna gtfo mpgh for a coouple hours[/SIZE][/COLOR][/FONT]
Quote Originally Posted by Kallisti View Post


Alright. This is pissing me off. It works when i re-wrote it the same in a new project.
just told you the problem ;o
Nah yo, it's cool. You're keeping this section alive. ;d
Quote Originally Posted by Void View Post
Nah yo, it's cool. You're keeping this section alive. ;d
lol... I think its the same 5 - 6 people who post in the c/c++ section... me, kallisti, void, brinuz, naghal and that other guy.




And kallisti, what book are you reading? I saw in one of your topics you were reading a book but I forget which one. It seems like a good book so I may get it.
Quote Originally Posted by Void View Post
Nah yo, it's cool. You're keeping this section alive. ;d
Oh well. I guess im staying then


edit :Request close is request
Sams teach yourself C++ in 1 hour a day.
Its not really 1 hour though. some chapters other than the very first couple ones took me a while.

Once again. Request close is request

but i started C++ when i was 11. im 13 now
Though i rage gave up a couple times untill i got this book
Quote Originally Posted by Kallisti View Post
Sams teach yourself C++ in 1 hour a day.
Its not really 1 hour though. some chapters other than the very first couple ones took me a while.

Once again. Request close is request

but i started C++ when i was 11. im 13 now
Though i rage gave up a couple times untill i got this book
really? mee too!! I rage quit c++ a few times, then I foud mpgh to be quite helpful and decided to just make simple useless applications following nobody's code, no books code. Basically taking what I learned and seeing what the **** it can do. Learning a few more things and seeing what they can do...


I started general coding when I was 10 years old. Started out with HTML, got quite far in that but then gave up cuz my mother wouldn't support it AT ALL. Did a bit of flash, made a few programs in VB, went on and created a couple games in c# using an engine, created a simple GUI program in c++ and quit programming at 13 talk about a mega-nerd.


anyways, I think I'll get that. If you rage quit c++ until getting this book, then it may be good for me as well.
Well, sometimes i get frustrated a lot and feel like ragequiting. But im determined to finish this book before school starts
Quote Originally Posted by Kallisti View Post
Well, sometimes i get frustrated a lot and feel like ragequiting. But im determined to finish this book before school starts
Ahh, yeah now that I'm 15 and not 12 I think I'll be able to dedicate myself to it... hopefully... Just downloaded stanza onto my desktop and ipod, also downloaded the book as an ebook, going to install the ebook into my ipod and start reading it thanks for the book ... After I read this, I'll read c++ primer plus.
Posts 1–15 of 20 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us