Consider this code...

This is a discussion on Consider this code... within the C++ Programming forums, part of the General Programming Boards category; If I had: Code: #include <string.h> class someClass { public: someClass(); private: void strlen(); }; void someClass::strlen() { // do ...

  1. #1
    Unregistered
    Guest

    Consider this code...

    If I had:

    Code:
    #include <string.h>
    
    class someClass 
    {
    public:
    someClass();
    private:
    void strlen();
    };
    
    void someClass::strlen()
    {
     // do something like exit(0);
    }
    How could i use the strlen() defined in string.h ?

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    If you want to use the strlen function directly with your class, that is so it could access private data of you class make it a friend by using the friend token. However the strlen() function is already defined so I'm not exactly sure what your asking.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    What is the purpose of
    void strlen();

  4. #4
    Unregistered
    Guest
    Well that was an example. I want to know how i can use native functions from a class with a member with the same name.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    317
    In c++ you may have many functions that have the same name as long as their signatures are different, that is their argument list. Therefore you could use a function called strlen() as long as it had a different argument list from the one defined in the String header file. For example:
    Code:
    int DoThis(void);
    int DoThis(int, double);
    int DoThis(char *);
    These functions all have different signatures and are therefore allowed to have the same name. I hope this helps.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    How could i use the strlen() defined in string.h ?
    std::strlen(/*whatever*/); or ::strlen(/*whatever*/); depending on how compliant your compiler is. Since you're including <string.h> it will probably be the latter. Try to make a habit out of using the new headers <cxxx> (so <string.h> becomes <cstring>).
    - lmov

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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