.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   Misc C++ things I have trouble understanding (http://forums.bots-united.com/showthread.php?t=1232)

Bill 02-04-2004 00:23

Misc C++ things I have trouble understanding
 
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.

Lazy 02-04-2004 00:56

Re: Misc C++ things I have trouble understanding
 
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.

Cheeseh 02-04-2004 00:57

Re: Misc C++ things I have trouble understanding
 
"Class" must have a lower case 'c' so it should be "class" and not "Class" :)

Cheeseh 02-04-2004 00:59

Re: Misc C++ things I have trouble understanding
 
lol :D damnit got there before me 8D

Bill 02-04-2004 01:32

Re: Misc C++ things I have trouble understanding
 
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.

MusicMan 02-04-2004 17:18

Re: Misc C++ things I have trouble understanding
 
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

koraX 02-04-2004 22:07

Re: Misc C++ things I have trouble understanding
 
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)

botmeister 02-04-2004 23:32

Re: Misc C++ things I have trouble understanding
 
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.

Pierre-Marie Baty 03-04-2004 03:05

Re: Misc C++ things I have trouble understanding
 
I disagree: at least MSVC 6 doesn't care about the case in the include files...

sPlOrYgOn 03-04-2004 03:49

Re: Misc C++ things I have trouble understanding
 
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.

Pierre-Marie Baty 03-04-2004 03:54

Re: Misc C++ things I have trouble understanding
 
Well there's a checkbox in your project settings...
it's called "disable compiler extensions", I think... :)

sPlOrYgOn 03-04-2004 04:41

Re: Misc C++ things I have trouble understanding
 
i haven't checked out all the options in MSVC6 yet cuz i recently moved to GNU/Linux and I just decided to use gcc on both to make life simpler

koraX 03-04-2004 11:32

Re: Misc C++ things I have trouble understanding
 
Quote:

Originally Posted by botmeister
This is nuts, must be Microsoft's way of locking you in. I recommend you use another compiler unless you don't care.

MSVC can be configured to work correctly (to support and compile ANSI standard code), but defaultly it adds Microsoft's shite (like precompiled headers and all that strange thing that Appwizard adds).
I'm using it, because I'm familiar with editor and it is easy to code in it (for me).

Also MSVC 6.0 added less microsoft's incompactible stuff than .NET

I'm working now on some program that has to run under linux, and using editors other than Visual studio would slow me down. So far, I 'encountered' these problems :
- MSVC adds #pragma once in header files, which is obsolete. G++ compiles without problems, but It is better to use #ifndef ... #define ... #endif
- MSVC uses precompiled header shite, and I had to change #include "StdAfx.h" to #include "stdafx.h" cause of case sensitivity on linux systems
- If you create a new class in Classview, the files MSVC creates are case sensitive so I had to covert them to lovercase. (#include "something" was lowercase ->OK)
- However, MSVC typed #include ".\something.h" so I had to change it to #include "something.h"
- MSVC .NET included <tchar.h> and added lot of shite like _tmain, and _tchar. It is UNICODE support and it is not ANSI standard imo, so I couldn't compile it under g++. I had to change _tmain to main and _TCHAR to char. ALso I had to remove #include <tchar.h> from stdafx.h
- If you change precompiled header (stdafx.h), it is pain to compile program in MSVC, 'cause MSVC forgets to compile it. You have to go to project properties and somewhere there under C++ tab, you must choose compile precompiled headers

after all those changes, code compiles well under linux, and program runs perfectly (I had to create makefile, indeed).

Also to note that if you srand(0) under windows and linux, it gives you another set of random numbers :(

After all these problems, I still use MSVC, cause I often do MFC programs under windows and MSVC .NET has some nice features like outlining and task list


All times are GMT +2. The time now is 18:20.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.