.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
Misc C++ things I have trouble understanding
Old
  (#1)
Bill
Guest
 
Status:
Posts: n/a
Default Misc C++ things I have trouble understanding - 02-04-2004

I find myself asking myself certain questions when I am programming C++. When I consult textbooks, I often find the answers cryptic, or over simplified. Lately, I have been experimenting with pointers and OOP.

I'll start with OOP. Here, I've written a program that declares a class for some of the properties of a gem, creates a gem named "bob", and within the main function, the characteristics for bob are declared then echoed back.

Code:
//*********************************
//Name: Bill					  *
//Project: OOP Experiment		 *
//Date: 3/31/04				   *
//*********************************
//Includes*************************
#include<iostream.h>
#include<lvp\string.h>
//*********************************
enum Color{red, blue, green, amber, violet};
enum Cut{diamond, marquis, oval, round, square};
//Gem******************************
Class Gem
{
 
 public:
  double height;
  double width;
  Color color;
  Cut cut;
  bool isCut (void);
  bool isPolished (void);
};
Gem bob;
//*********************************
 
//Main*****************************
int main()
{
 
 bob.height=5;
 bob.width=3;
 bob.color=blue;
 bob.cut=diamond;
 
 cout << "Here\'s some stuff about Bob\'s Gem: " << endl;
 cout << "The height: " << bob.height << endl;
 cout << "The width: " << bob.width << endl;
 cout << "The color: " << bob.color << endl;
 cout << "The cut: " << bob.cut << endl;
 return(0);
}
//*********************************
I don't know whether or not I'm doing this right, so if I'm not, please, let me know. I know to the compiler I'm not doing it right, because when I attempt to compile, I recieve 3 errors:

Code:
--------------------Configuration: oop - Win32 Debug--------------------
Compiling...
object.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : error C2146: syntax error : missing ';' before identifier 'Gem'
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : error C2501: 'Class' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\oop\object.cpp(17) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

object.obj - 3 error(s), 0 warning(s)
I'm in my first semester of C++, and we haven't covered OOP yet, and we won't cover pointers at all. If anyone has a good tutorial on pointers, I'd appreciate it. I would also appreciate it if someone could help me with my OOP woes.

I guess I seem like a C++ n00b, but we all have to start somewhere, I guess.
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#2)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

You need to change "Class" to "class".
If you look carefully at the errors ( Specifically #1 ) that the compiler has outputted you'll see what's wrong.

All C++ keywords are case-sensitive so typing Class or Struct is not the same as class or struct.
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#3)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

"Class" must have a lower case 'c' so it should be "class" and not "Class"
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#4)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

lol damnit got there before me 8D
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#5)
Bill
Guest
 
Status:
Posts: n/a
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

ugh, one shift key mix-up, and three errors sprout up. I thought class was uppercase because they are uppercase in Botman's C++ tutorial...

damn shift key....


damn.
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#6)
MusicMan
Member
 
Status: Offline
Posts: 236
Join Date: Feb 2004
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

it looks like the reason for the three errors is 1: because of class being written with a uppercase 'C' . error 2: the compiler gets confused cause when you used the uppercase C it probably thinks you are declaring a variable with Class as a type and wants the ; to end the sentence. error 3 is probably due to line 17 being an invalid code. Am I on the right track?

MusicMan

Last edited by MusicMan; 02-04-2004 at 18:20..
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#7)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: Misc C++ things I have trouble understanding - 02-04-2004

also remember that everything is case sensitive in C/C++, even filenames. Micro$oft visual studio does not correctly handles file names (create some project and see: stdafh.h is name of file and in source code, Visual .NET types #include <StdAfx.h> which of course will rin on Windows(tm) machines but won't even compile on Linux)


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#8)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: Misc C++ things I have trouble understanding - 03-04-2004

Quote:
Originally Posted by koraX
also remember that everything is case sensitive in C/C++, even filenames. Micro$oft visual studio does not correctly handles file names (create some project and see: stdafh.h is name of file and in source code, Visual .NET types #include <StdAfx.h> which of course will rin on Windows(tm) machines but won't even compile on Linux)
This is nuts, must be Microsoft's way of locking you in. I recommend you use another compiler unless you don't care.


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#9)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Misc C++ things I have trouble understanding - 03-04-2004

I disagree: at least MSVC 6 doesn't care about the case in the include files...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Misc C++ things I have trouble understanding
Old
  (#10)
sPlOrYgOn
<-- He did it.
 
sPlOrYgOn's Avatar
 
Status: Offline
Posts: 1,558
Join Date: Jan 2004
Location: Los Angeles, California, USA, North America, Earth, Solar System, Milky Way.
Default Re: Misc C++ things I have trouble understanding - 03-04-2004

theres something about the MSVC6 compiler i hate..
i think its all the extra crap they put in a program that gcc doesn't do.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com