Thread: Questions on Classes

  1. #1
    Registered User
    Join Date
    Nov 2003

    Questions on Classes

    I have studied C and am just starting to study OOP in C++. I have read lesson 12 on Intro to Classes.

    It seems that functions in C and classes in C++ are quite similar.
    Both can carry out operations within themselves and the code of classes and functions can be reused. Both classes and functions may also require input data in order to carry out their operations right? So, what is the big difference between functions and classes?

    Constructors are used for initializing variables. So if we have variables that do not need initialization, does that mean we need not have a constructor? Are there other uses for the constructor besides initialization?

    I have also heard from many programming students that OOP programming is much more difficult than structured programming e.g C. Is this true?

    Please reply......thanks!

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Phildelphia, PA
    OOP looks at the world as one would normally do so. There are objects that all have methods and properties. A well designed class is great. It's good design that trips up most people.

    As for the similarities between functions and classes, I don't think that's going to help you. C++ has functions just like C. Just think of a class like any other thing. A dog has properties like age, breed, height, weight, etc. A dog has methods like eat, bark, make a mess, etc. I'd suggest Eckle's book Thinking in C++. It's free online.

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    You need to understand what is meant by the following terms that describe OOP classes

    - encapsulation
    - inheritance
    - polymorphism

    You'll probably learn them in that order, I'd guess. Once understand the basics of these, you'll be able to answer your own question.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions about classes(implementation files)
    By Link_26 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2006, 09:48 AM
  2. Classes being able to use other classes functions
    By rainmanddw in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2006, 11:19 AM
  3. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  4. 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
  5. 2 questions - classes and variables
    By phantom in forum C++ Programming
    Replies: 8
    Last Post: 09-25-2001, 09:22 PM