473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Jul 19 '05 #1
3 2012
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.
Jul 19 '05 #2
partybob99 <pa********@hotmail.com> spoke thus:
void main()


Regardless of whether you're compiling in C or C++ mode, main() must return an
int. void main() is a non-standard prototype and you shouldn't use it. The
FAQ may prove to be interesting reading:

http://www.parashift.com/c++-faq-lit....html#faq-29.3

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 19 '05 #3
"partybob99" <pa********@hotmail.com> wrote in message
news:df**************************@posting.google.c om...
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.

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.


--
Gary
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vitamin | last post by:
I have written a JAVA class it have compiled with -target 1.1 arguement and I just can instant it twice time. (said, I can instant it at the first time and second time). When I try to instant it...
3
by: tt | last post by:
# g++ cdr0frprep.cpp In file included from /usr/local/include/c++/3.2.3/backward/strstream:51, from /usr/local/include/c++/3.2.3/backward/strstream.h:33, from cdr0frprep.cpp:5:...
3
by: דורון חסידים | last post by:
Hellow, I am a teacher, and trying to install a copy of visual studio .net that received from my school. I insert CD1, klick setup, klick the only option available ''siprerequites'', and than...
1
by: kmcq | last post by:
I've contacted my host and they have no idea what connection string I need to use to access the MS SQL database we have running on their equipment. I'm trying to connection from ASP using OLE. ...
0
by: mountainbig | last post by:
I have the following tables with the following Coumns Product -- Partnumber, description, shortcodeid Shortcc -- shortcodeid module -- moduleid, shortcodeid Salesitem -- salesorderid,...
1
by: shivkumarvk | last post by:
i want to build such a program that should listen to perticular port and reads data from that port continuosly. please help me to build this
5
by: simonyong | last post by:
I'm newbie to .net and currently learning to use BLOB to insert image into database What i'm facing is i dont know what is going wrong to make me continue getting this error: An unhandled...
1
by: DarkGiank | last post by:
Hi, im new to csharp and im trying to create a class that can change the application database without no rewriting all connection code... but cause some reason it is not working... it tells me that...
3
by: ciqeane | last post by:
here is the sample data CREATE TABLE Boo ( keycol INT PRIMARY KEY, datacol VARCHAR(20)); INSERT INTO Boo VALUES(1, 'DM/B19S/7281520'); INSERT INTO Boo VALUES(2, 'NW/L11U/BALL 10/300');...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.