for whom the header files are important?

Discussion in 'C++' started by yogpjosh@gmail.com, Dec 10, 2006.

  1. Guest

    Hi,

    for whom the header files are important?

    for the programmer or for the compiler..??
    As the programmer very well sees all the private data of a class
    through the header file ..but if he tries to access it then the
    compiler throws the error..


    Thanks and Regards,
    Yogesh Joshi
    , Dec 10, 2006
    #1
    1. Advertising

  2. wrote:
    > Hi,
    >
    > for whom the header files are important?
    >
    > for the programmer or for the compiler..??
    > As the programmer very well sees all the private data of a class
    > through the header file ..but if he tries to access it then the
    > compiler throws the error..



    Header files allow you to create "interfaces" and reusability of code.

    As for private data, you can, if you wish, hide all your private
    elements in the cpp file.
    Gianni Mariani, Dec 10, 2006
    #2
    1. Advertising

  3. Kai-Uwe Bux Guest

    wrote:


    > for whom the header files are important?
    >
    > for the programmer or for the compiler..??


    The compiler.

    > As the programmer very well sees all the private data of a class
    > through the header file ..but if he tries to access it then the
    > compiler throws the error..


    The programmer is supposed to read the documentation/specs. Stuff in the
    headers are implementation details.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Dec 10, 2006
    #3
  4. Salt_Peter Guest

    wrote:
    > Hi,
    >
    > for whom the header files are important?
    >
    > for the programmer or for the compiler..??
    > As the programmer very well sees all the private data of a class
    > through the header file ..but if he tries to access it then the
    > compiler throws the error..
    >
    >
    > Thanks and Regards,
    > Yogesh Joshi


    As far as the compiler is concerned, header files don't exist.
    That is, until you include them into your source(s).
    And nothing stops you from accessing the private parts of a class,
    either.
    Thats what accessors and public member functions are for.
    Compilers generate errors because the declaration of the class is a set
    of rules the compiler must obey and enforce.
    Salt_Peter, Dec 10, 2006
    #4
  5. Signal9 Guest

    wrote:
    > Hi,
    >
    > for whom the header files are important?
    >
    > for the programmer or for the compiler..??
    > As the programmer very well sees all the private data of a class
    > through the header file ..but if he tries to access it then the
    > compiler throws the error..
    >
    >
    > Thanks and Regards,
    > Yogesh Joshi


    You should read a C++ book please.
    Signal9, Dec 11, 2006
    #5
  6. Guest

    Salt_Peter wrote:
    > wrote:
    > > Hi,
    > >
    > > for whom the header files are important?
    > >
    > > for the programmer or for the compiler..??
    > > As the programmer very well sees all the private data of a class
    > > through the header file ..but if he tries to access it then the
    > > compiler throws the error..
    > >
    > >
    > > Thanks and Regards,
    > > Yogesh Joshi

    >
    > As far as the compiler is concerned, header files don't exist.
    > That is, until you include them into your source(s).
    > And nothing stops you from accessing the private parts of a class,
    > either.
    > Thats what accessors and public member functions are for.
    > Compilers generate errors because the declaration of the class is a set
    > of rules the compiler must obey and enforce.


    Yes..got it..merely seeing the private variables doesn't mean you have
    access to that..

    Thanks and Regards,
    Yogesh Joshi
    , Dec 11, 2006
    #6
  7. Salt_Peter Guest

    wrote:
    > Salt_Peter wrote:
    > > wrote:
    > > > Hi,
    > > >
    > > > for whom the header files are important?
    > > >
    > > > for the programmer or for the compiler..??
    > > > As the programmer very well sees all the private data of a class
    > > > through the header file ..but if he tries to access it then the
    > > > compiler throws the error..
    > > >
    > > >
    > > > Thanks and Regards,
    > > > Yogesh Joshi

    > >
    > > As far as the compiler is concerned, header files don't exist.
    > > That is, until you include them into your source(s).
    > > And nothing stops you from accessing the private parts of a class,
    > > either.
    > > Thats what accessors and public member functions are for.
    > > Compilers generate errors because the declaration of the class is a set
    > > of rules the compiler must obey and enforce.

    >
    > Yes..got it..merely seeing the private variables doesn't mean you have
    > access to that..
    >
    > Thanks and Regards,
    > Yogesh Joshi


    Not neccessarily true.

    class N
    {
    int n;
    public:
    N() : n(0) { }
    void set(int x) { n = x; }
    int get() const { return n; }
    };

    I can see, modify and access the private integer n.
    Salt_Peter, Dec 11, 2006
    #7
  8. Guest

    Salt_Peter wrote:
    > wrote:
    > > Salt_Peter wrote:
    > > > wrote:
    > > > > Hi,
    > > > >
    > > > > for whom the header files are important?
    > > > >
    > > > > for the programmer or for the compiler..??
    > > > > As the programmer very well sees all the private data of a class
    > > > > through the header file ..but if he tries to access it then the
    > > > > compiler throws the error..
    > > > >
    > > > >
    > > > > Thanks and Regards,
    > > > > Yogesh Joshi
    > > >
    > > > As far as the compiler is concerned, header files don't exist.
    > > > That is, until you include them into your source(s).
    > > > And nothing stops you from accessing the private parts of a class,
    > > > either.
    > > > Thats what accessors and public member functions are for.
    > > > Compilers generate errors because the declaration of the class is a set
    > > > of rules the compiler must obey and enforce.

    > >
    > > Yes..got it..merely seeing the private variables doesn't mean you have
    > > access to that..
    > >
    > > Thanks and Regards,
    > > Yogesh Joshi

    >
    > Not neccessarily true.
    >
    > class N
    > {
    > int n;
    > public:
    > N() : n(0) { }
    > void set(int x) { n = x; }
    > int get() const { return n; }
    > };
    >
    > I can see, modify and access the private integer n.


    >>>>Yes..got it..merely seeing the private variables doesn't mean you have
    >>>>>access to that..

    sorry ..what I mean to say was..accessing the private variables
    directly..i.e without using any member functions..
    (I also come across this statement that " getter and setter functions
    reveal the internal implementation details of the class and should be
    avoided..")

    cheers,
    Yogesh Joshi
    , Dec 11, 2006
    #8
  9. Noah Roberts Guest

    wrote:
    > Salt_Peter wrote:
    > > wrote:
    > > > Salt_Peter wrote:
    > > > > wrote:
    > > > > > Hi,
    > > > > >
    > > > > > for whom the header files are important?
    > > > > >
    > > > > > for the programmer or for the compiler..??
    > > > > > As the programmer very well sees all the private data of a class
    > > > > > through the header file ..but if he tries to access it then the
    > > > > > compiler throws the error..
    > > > > >
    > > > > >
    > > > > > Thanks and Regards,
    > > > > > Yogesh Joshi
    > > > >
    > > > > As far as the compiler is concerned, header files don't exist.
    > > > > That is, until you include them into your source(s).
    > > > > And nothing stops you from accessing the private parts of a class,
    > > > > either.
    > > > > Thats what accessors and public member functions are for.
    > > > > Compilers generate errors because the declaration of the class is a set
    > > > > of rules the compiler must obey and enforce.
    > > >
    > > > Yes..got it..merely seeing the private variables doesn't mean you have
    > > > access to that..
    > > >
    > > > Thanks and Regards,
    > > > Yogesh Joshi

    > >
    > > Not neccessarily true.
    > >
    > > class N
    > > {
    > > int n;
    > > public:
    > > N() : n(0) { }
    > > void set(int x) { n = x; }
    > > int get() const { return n; }
    > > };
    > >
    > > I can see, modify and access the private integer n.

    >
    > >>>>Yes..got it..merely seeing the private variables doesn't mean you have
    > >>>>>access to that..

    > sorry ..what I mean to say was..accessing the private variables
    > directly..i.e without using any member functions..


    You still can, but only if you abuse the system:

    N n;
    int * n_member = reinterpret_cast<int*>(&n);
    n_member = 5;
    Noah Roberts, Dec 11, 2006
    #9
  10. Noah Roberts wrote:
    ....
    > You still can, but only if you abuse the system:
    >
    > N n;
    > int * n_member = reinterpret_cast<int*>(&n);
    > n_member = 5;
    >


    did you mean:

    N n;
    int & n_member = * reinterpret_cast<int*>(&n);
    n_member = 5;

    ?
    Gianni Mariani, Dec 11, 2006
    #10
  11. Guest

    Gianni Mariani wrote:
    > Noah Roberts wrote:
    > ...
    > > You still can, but only if you abuse the system:
    > >
    > > N n;
    > > int * n_member = reinterpret_cast<int*>(&n);
    > > n_member = 5;
    > >

    >
    > did you mean:
    >
    > N n;
    > int & n_member = * reinterpret_cast<int*>(&n);
    > n_member = 5;
    >
    > ?


    but those are the intentional (illegal??) activities of the programmer
    ..But compiler will complain if the programmer writes

    n.n //access denied..

    so that means the header files are for compiler..

    cheers,
    Yogesh Joshi
    , Dec 12, 2006
    #11
  12. Salt_Peter Guest

    wrote:
    > Gianni Mariani wrote:
    > > Noah Roberts wrote:
    > > ...
    > > > You still can, but only if you abuse the system:
    > > >
    > > > N n;
    > > > int * n_member = reinterpret_cast<int*>(&n);
    > > > n_member = 5;
    > > >

    > >
    > > did you mean:
    > >
    > > N n;
    > > int & n_member = * reinterpret_cast<int*>(&n);
    > > n_member = 5;
    > >
    > > ?

    >
    > but those are the intentional (illegal??) activities of the programmer
    > .But compiler will complain if the programmer writes
    >
    > n.n //access denied..
    >
    > so that means the header files are for compiler..


    Again, as far as the compiler is concerned, header files don't exist.
    Thats why you need to include them into source(s).
    Salt_Peter, Dec 12, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2VubmV0aCBQ?=

    To whom should I address complaints?

    =?Utf-8?B?S2VubmV0aCBQ?=, Jan 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    347
    =?Utf-8?B?S2VubmV0aCBQ?=
    Jan 20, 2005
  2. Eric Woudenberg
    Replies:
    1
    Views:
    361
    Miki Tebeka
    May 19, 2004
  3. John Smith

    Header files included in header files

    John Smith, Jul 21, 2004, in forum: C Programming
    Replies:
    18
    Views:
    596
    Jack Klein
    Jul 24, 2004
  4. Replies:
    3
    Views:
    1,277
    Walter Roberson
    May 1, 2006
  5. mlt
    Replies:
    2
    Views:
    813
    Jean-Marc Bourguet
    Jan 31, 2009
Loading...

Share This Page