-
Classes Help
Header File:
Code:
#ifndef __Assign5__h
#define __Assign5__h
#include <iostream.h>
#include <iomanip.h>
class cSTRING
{
public:
//Members Variables
char* cStr;
int nLen;
//Constructors
cSTRING(char cStr = '\0', int nLen=0);
cSTRING(char* cStr);
//Destructor
~cSTRING();
//Prototypes
int SetStringLength(char*);
char* SetStringCopy(char*,char*);
//Inspectors
const int GetStringLength( cSTRING& str );
const char* GetString();
//Methods
void Display (cSTRING& str);
}
#endif
CPP FILE:
Code:
#include <iostream.h>
#include "Assign5.h"
void main (void)
{
cSTRING str;
int nStrLen;
char str[50];
cout << "Enter a String: ";
cin >> str;
}
i am getting these errors:
error C2143: syntax error : missing ';' before 'PCH creation point'
error C2040: 'str' : 'class cSTRING' differs in levels of indirection from 'char [50]'
-
You should put a ';' after the definition of the class:
-
Just quickly glancing over your code:
Code:
class someclasss
{
};<---
-
>#ifndef __Assign5__h
>#define __Assign5__h
One underscore == bad. Two underscore == really really really really really really really really really really really really really really really really really really really okay I think that's enough. Just don't use two leading underscores, kay? For that matter, don't use a leading underscore and an uppercase letter either. :)
>#include <iostream.h>
>#include <iomanip.h>
Drop the .h, these are no longer correct C++ headers.
>void main (void)
int main(), no exceptions. Well, except for the handful of exceptions, but they're pretty exceptional, so just pretend there are no exceptions.
>char str[50];
You already declared a variable called str.
-
>Well, except for the handful of exceptions, but they're pretty exceptional, so just pretend there are no exceptions.
what are the exceptions?
-
Basically, if you aren't returning control to anything, it's considered acceptable (kernels, imbedded OS's, etc).
-
>what are the exceptions?
When main takes arguments:
Code:
int main ( int argc, char **argv )
When the compiler supports extensions:
Code:
int main ( int argc, char **argv, char **envp )
On a freestanding implementation all restrictions are off. You can pretty much do what you want because the standard doesn't impose any limitations on you. That's the only case where void main would be valid.