Like Tree1Likes
  • 1 Post By manasij7479

objects and classes in inheritance

This is a discussion on objects and classes in inheritance within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I have just made a program of class in which their are base and derived classes . The ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    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:
    ------------------------------------------------------------------

    Code:
    class Vehicle
    {
    private:
    char Name;
    string id;
    
    public:
    void getName();
    void setName();
    void setid();
    void getid();
    
    };
    
    
    main()
    {
    Vehicle veht; 
    // These are the functions I am using to access the data members of the class Vehicle/
    veht.getName();
    veht.getid();
    
    }
    ---------------------------------------------------------------
    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.
    Thanks

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

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Do what laserlight said in your earlier thread and then rethink this question.
    antred likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,583
    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
    Posts
    100
    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, 11:39 AM
  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, 09:43 PM
  5. Classes & Inheritance
    By TankCDR in forum C++ Programming
    Replies: 5
    Last Post: 03-09-2002, 05:25 PM

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