problem with a class/object (simple)

Started by
3 comments, last by trixorz 15 years, 10 months ago
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; }
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.
------------Anything prior to 9am should be illegal.
ah yes, it is working now, hehe

thanks a bunch :D


btw how did you post the code in a code box?
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]
ah, nice thans you for the tip about clicking edit to get the mark ups =D

This topic is closed to new replies.

Advertisement