-
Making new classes
I need to know how to make new classes. I tried looking at the lesson posted on this site, but that didn't help. I tried using the sample code from lesson 12, but got these strange and exotic errors
C:\Program Files\DevStudio\SharedIDE\bin\Cpp1.cpp(1) : error C2653: 'Aclass' : is not a class or namespace name
C:\Program Files\DevStudio\SharedIDE\bin\Cpp1.cpp(3) : error C2065: 'cout' : undeclared identifier
C:\Program Files\DevStudio\SharedIDE\bin\Cpp1.cpp(3) : error C2297: '<<' : bad right operand
C:\Program Files\DevStudio\VC\INCLUDE\ostream.h(145) : error C2371: 'cout' : redefinition; different basic types
Anything helpful on the subject would be appreciated.
-
Code:
class myclass
{
private:
int val;
char character;
public:
myclass (int newVal, char newChar);
void display (void);
};
// Constructor - called every time a new instance is generated or allocated with new:
myclass::myclass (int newVal, char newChar)
{
val = newVal;
character = newChar;
}
// Other member functions.
void myclass::display (void)
{
cout << val << ", " << character << ".\n";
}
main (void)
{
myclass c1 (34, 'f'); // Static object.
myclass *c2 = new myclass (78, 't'); // Dynamically allocated object.
c1.display ();
c2->display (); // Note the different way of accessing dynamic class members.
delete c2;
}
-
And it looks to me like you've not included <iostream.h>