Please Help!! I can't figure out how to build the simplest class

P

partybob99

I am using Microsoft Visual C++ v1.52. I am trying to build the most
simple class known to mankind, and I cant get it to compile no matter
what I do. I am building the program as a .LIB file and not an .EXE.

I've taken the code from a tutorial manual so the syntax should be
correct.

Here is the code:

class Cat // declare the class object
{
public: // members which follow are public
int itsAge;
int itsWeight;
};

void main()
{
Cat Frisky;
Frisky.itsAge = 5; // assign to the member variable
}

I take this code and paste it into a new .c file and then try to
build. I get the following errors:

error C2282: 'class' is followed by 'Cat' (missing ','?)
error C2065: 'Cat' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'Frisky'
error C2065: 'Frisky' : undeclared identifier
error C2224: left of '.itsAge' must have class/struct/union type

Does anyone know what is going on here? I know "class" is a valid
keyword, but it's like the compiler does not that it's a valid
keyword. I apologize to everyone for being such a moron, but I need
assistance.

Thanks in advance.
Partybob99
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

partybob99 escribió:
I take this code and paste it into a new .c file and then try to

That way you are compiling it as a C program, not C++. Use a .cpp file
instead.

Regards.
 
G

Gary Labowitz

partybob99 said:
I am using Microsoft Visual C++ v1.52. I am trying to build the most
simple class known to mankind, and I cant get it to compile no matter
what I do. I am building the program as a .LIB file and not an .EXE.

I've taken the code from a tutorial manual so the syntax should be
correct.

Here is the code:

class Cat // declare the class object
{
public: // members which follow are public
int itsAge;
int itsWeight;
};

void main()
{
Cat Frisky;
Frisky.itsAge = 5; // assign to the member variable
}

I take this code and paste it into a new .c file and then try to
build. I get the following errors:

Try naming your file .cpp and recompile. You are telling VC++ to compile C
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top