Thread: Making new classes

  1. #1
    Unregistered
    Guest

    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.

  2. #2
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    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;
    }
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  3. #3
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    And it looks to me like you've not included <iostream.h>
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  2. Questions on Classes
    By Weng in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2003, 06:49 AM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. Sharing a variable between classes of different .CPP files
    By divingcrab in forum C++ Programming
    Replies: 5
    Last Post: 07-07-2002, 02:57 PM