Thread: objects and classes in inheritance

  1. #1
    Registered User
    Join Date
    Nov 2011

    objects and classes in inheritance

    Hi guys,
    I have just made a program of class in which their are base and derived classes . The program is as follows:

    class Vehicle
    char Name;
    string id;
    void getName();
    void setName();
    void setid();
    void getid();
    Vehicle veht; 
    // These are the functions I am using to access the data members of the class Vehicle/
    In the main() part of the program I have made the object "veht" for the class Vehicle so I can access the "Name" and "id" of the class Vehicle from outside of the class.
    Now will I be able to access the private data members "Name" and "id" of the class Vehicle using the functions that I have written in main()?

    Pls correct me if I am wrong.

    Last edited by student111; 06-12-2012 at 04:20 AM. Reason: adding more

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Do what laserlight said in your earlier thread and then rethink this question.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Is this your real code or just some pseudo code?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    May 2006
    You're on the right track, but there are two problems at the moment:

    #1: The functions getName() and getid() each need to return something. In this case it's Name and id, respectively. Since they need to return something, they're not going to work if you declare their return types as void. That's only used for functions that won't return anything.

    #2: The functions getName() and getid() will basically do and only do whatever you tell them. In the code you've provided, you haven't given them any instrunctions (bodies). Even if you didn't declare them to be void, we couldn't tell if you can get veht's Name and id out of them, because we don't see those instructions, and because the names of the functions are irrelevant to their functionality in terms of what the computer cares about.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with classes and inheritance!!
    By alacahzam in forum C++ Programming
    Replies: 9
    Last Post: 03-18-2011, 11:39 AM
  2. Inheritance of objects and linked list
    By rakeshkool27 in forum C++ Programming
    Replies: 7
    Last Post: 11-11-2010, 12:39 PM
  3. how to refer to base objects created during inheritance??
    By rahulsk1947 in forum C++ Programming
    Replies: 2
    Last Post: 05-06-2007, 08:41 PM
  4. help in inheritance classes
    By Agnesa in forum C++ Programming
    Replies: 7
    Last Post: 03-11-2003, 10:43 PM
  5. Classes & Inheritance
    By TankCDR in forum C++ Programming
    Replies: 5
    Last Post: 03-09-2002, 06:25 PM