Making new classes

This is a discussion on Making new classes within the C++ Programming forums, part of the General Programming Boards category; I need to know how to make new classes. I tried looking at the lesson posted on this site, but ...

  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
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    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;
    }
    MSVC++ 6.0

  3. #3
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    And it looks to me like you've not included <iostream.h>
    MSVC++ 6.0

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, 08:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04: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, 03:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21