problem with a class/object (simple)
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;
}
Make sure there is a semicolon ';' at the end of your class definition:
Without it, you will get the C2533 error.
class Foo{ // .... code ...}; // <-- Semicolon
Without it, you will get the C2533 error.
Place your code in source tags.
[source]
// code here
[/source]
It will look like this:
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]
[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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement