Jump to content
  • Advertisement
Sign in to follow this  
trixorz

problem with a class/object (simple)

This topic is 3646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

currently I'm trying to learn myself c++ and i got a problem with a class I'm trying to make, my compiler (visual c++ express edition 2008) gives me this error 1>c:\users\trixed\documents\visual studio 2008\projects\hello_world\hello_world\hello.cpp(5) : error C2533: 'Cat::{ctor}' : constructors not allowed a return type as far as i can see in my code i don't declare a return type for it, can anyone help me with it? and here is my code: class.h class Cat { public: Cat (int initialAge); ~Cat(); int GetAge() const {return itsAge;} void SetAge(int age) { itsAge = age;} void Meow() const {std::cout << "Meow.\n";} private: int itsAge; } and hello.cpp #include <iostream> #include "class.h" Cat::Cat(int initialAge) { itsAge = initialAge; } Cat::~Cat() { } int main() { Cat Frisky(5); Frisky.Meow(); std::cout << "Frisky is a cat who is "; std::cout << Frisky.GetAge() << " years old.\n"; Frisky.Meow(); Frisky.SetAge(7); std::cout << "Now Frisky is "; std::cout << Frisky.GetAge() << " years old.\n"; return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Make sure there is a semicolon ';' at the end of your class definition:


class Foo
{
// .... code ...
}; // <-- Semicolon



Without it, you will get the C2533 error.

Share this post


Link to post
Share on other sites
Place your code in source tags.

[source]

// code here

[/source]

It will look like this:



// code here




Click "edit" on my (or any) post when you want to see the actual markup. You won't really be able to edit my post though [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!