avoid function overloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rahul

    avoid function overloading

    Hi Everyone,

    I have a function defined in a source file,


    sample.cpp

    int doit()
    {
    cout<<"in doit function"<<endl ;
    }

    Now i need to make sure that this function is not overloaded by other
    developers, is there anyway to ensure the same?
  • Andrey Tarasevich

    #2
    Re: avoid function overloading

    Rahul wrote:
    I have a function defined in a source file,
    >
    >
    sample.cpp
    >
    int doit()
    {
    cout<<"in doit function"<<endl ;
    }
    >
    Now i need to make sure that this function is not overloaded by other
    developers, is there anyway to ensure the same?
    No, there's no way to ensure anything like that.

    Although it is not immediately clear what you mean by "this function". Function
    'doit(void)' cannot be "overloaded " from what you defined it to be. Function
    'doit' with a different set of parameters can be.

    --
    Best regards,
    Andrey Tarasevich

    Comment

    • Rahul

      #3
      Re: avoid function overloading

      On Mar 24, 7:08 pm, Andrey Tarasevich <andreytarasev. ..@hotmail.com>
      wrote:
      Rahul wrote:
      I have a function defined in a source file,
      >
      sample.cpp
      >
      int doit()
      {
      cout<<"in doit function"<<endl ;
      }
      >
      Now i need to make sure that this function is not overloaded by other
      developers, is there anyway to ensure the same?
      >
      No, there's no way to ensure anything like that.
      >
      Although it is not immediately clear what you mean by "this function". Function
      'doit(void)' cannot be "overloaded " from what you defined it to be. Function
      'doit' with a different set of parameters can be.
      >
      --
      Best regards,
      Andrey Tarasevich
      Yes, i meant, i don't want any other developer to have the same
      function name with different set of arguements...

      Comment

      • ciccio

        #4
        Re: avoid function overloading

        Rahul wrote:
        Hi Everyone,
        >
        I have a function defined in a source file,
        >
        >
        sample.cpp
        >
        int doit()
        {
        cout<<"in doit function"<<endl ;
        }
        >
        You have to see function overloading a bit like using identical function
        names with different argument list. there is more to it, but this could
        be the crude idea. So can somebody overload
        int doit();

        The answer is no

        but he can overload
        output doit(with_this) ;

        Obviously a developer can always overload int doit() by directly
        altering your code, or if you don't give him your code, he can just kick
        it out of the library and incorporate his own.

        Comment

        • ciccio

          #5
          Re: avoid function overloading

          Yes, i meant, i don't want any other developer to have the same
          function name with different set of arguements...
          Then I think you would need to create all those functions yourself with
          bogus and incorporate them in a library.

          Comment

          • Default User

            #6
            Re: avoid function overloading

            Rahul wrote:

            Yes, i meant, i don't want any other developer to have the same
            function name with different set of arguements...

            Why?




            Brian

            Comment

            • Matt  Havener

              #7
              Re: avoid function overloading

              On Mar 24, 12:03 pm, "Default User" <defaultuse...@ yahoo.comwrote:
              Rahul wrote:
              Yes, i meant, i don't want any other developer to have the same
              function name with different set of arguements...
              >
              Why?
              >
              Brian
              I think there is a symbol table option that errors on a collision. I
              had a similar issue with 3rd party libraries and some global symbols.
              To avoid this problem entirely, use namespaces, scope everything as
              tiny as possible, and prepend names (if you're using pure C). E.g.,
              MySection::doit () or MySection_doit( ).

              Comment

              • Rahul

                #8
                Re: avoid function overloading

                On Mar 24, 5:38 pm, Rahul <sam_...@yahoo. co.inwrote:
                Hi Everyone,
                >
                I have a function defined in a source file,
                >
                sample.cpp
                >
                int doit()
                {
                cout<<"in doit function"<<endl ;
                >
                }
                >
                Now i need to make sure that this function is not overloaded by other
                developers, is there anyway to ensure the same?
                extern "C"
                {
                #include <sample.h>
                }

                I would have the prototype of my function in the header file. I would
                expect other developers to put in their prototypes too in the header
                file as and when they include their overloaded function's prototype in
                the header file, g++ compiler would give a compilation error...

                Comment

                • Ian Collins

                  #9
                  Re: avoid function overloading

                  Rahul wrote:
                  On Mar 24, 5:38 pm, Rahul <sam_...@yahoo. co.inwrote:
                  >Hi Everyone,
                  >>
                  > I have a function defined in a source file,
                  >>
                  >sample.cpp
                  >>
                  >int doit()
                  >{
                  > cout<<"in doit function"<<endl ;
                  >>
                  >}
                  >>
                  > Now i need to make sure that this function is not overloaded by other
                  >developers, is there anyway to ensure the same?
                  >
                  extern "C"
                  {
                  #include <sample.h>
                  }
                  >
                  I would have the prototype of my function in the header file. I would
                  expect other developers to put in their prototypes too in the header
                  file as and when they include their overloaded function's prototype in
                  the header file, g++ compiler would give a compilation error...
                  >
                  Put the (conditionally compiled for C++) extern "C" wrapper in the header.

                  --
                  Ian Collins.

                  Comment

                  • Andrey Tarasevich

                    #10
                    Re: avoid function overloading

                    Rahul wrote:
                    ...
                    extern "C"
                    {
                    #include <sample.h>
                    }
                    >
                    I would have the prototype of my function in the header file. I would
                    expect other developers to put in their prototypes too in the header
                    file as and when they include their overloaded function's prototype in
                    the header file, g++ compiler would give a compilation error...
                    ...
                    So, what you said above, is it a part of the original question or the answer to
                    the original question?

                    --
                    Best regards,
                    Andrey Tarasevich

                    Comment

                    Working...