Thread: how do i create a class

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1

    how do i create a class

    how do i create a class called Largest thatworks with only unsigned long values with the following methods(functions)
    Largest()
    bool getnext()
    unsigned long value()const

    i need help how to begin
    i need
    Largest.h
    Largest.cpp
    and largestDriver.cpp()
    to be included as my files

    also how do i protect Largest.h from the mulitple inclusion with the #pragma once tag.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: how do i create a class

    Originally posted by chanuajohnson
    how do i create a class called Largest thatworks with only unsigned long values with the following methods(functions)
    Largest()
    bool getnext()
    unsigned long value()const

    i need help how to begin
    i need
    Largest.h
    Largest.cpp
    and largestDriver.cpp()
    to be included as my files

    also how do i protect Largest.h from the mulitple inclusion with the #pragma once tag.
    Don't use #pragma once it is compiler specific. Here is what your H file might look like, keep in mind you will have to write the function implementation in the accompanying cpp file.

    Code:
    #ifndef LARGEST_H 
    #define LARGEST_H
    
    class Largest
    {
      private:
        unsigned long m_foo;
        unsigned long m_foo2;
    
      public:
        Largest( ); // Constructor
        ~Largest( ); // Destructor
        bool getNext( );
        unsigned long value( ) const;
    };
    
    #endif /* LARGEST_H */
    Use those #ifndef's for inclusion guards instead of #pragma once. Post back if you have more questions.

    OOPS: To create an instance of this class in your main code, simply use the following syntax.

    Largest MyLargeList;

    Where Largest is the class you want to create an instance of and MyLargeList is the variable name.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on class coupling
    By andrea72 in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2011, 10:16 AM
  2. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  3. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM