Need Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Velhari
    New Member
    • Sep 2006
    • 46

    #1

    Need Help

    Hi all,

    Tell me why C doesnt have Nested Function?
    Please reply me....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Velhari
    Hi all,

    Tell me why C doesnt have Nested Function?
    Please reply me....
    Nested function? I've never programmed in a laguage with nested functions.

    Comment

    • macklin01
      New Member
      • Aug 2005
      • 145

      #3
      I wasn't sure what you meant by nested functions until I found this wikipedia entry. It reminds me a lot of a "subfunctio n" in matlab.

      Well, C++ doesn't have nested functions, but some elements of it are here. For instance, a class can have a private function:

      Code:
      class Demo{
      private:
       double* data;
       int size;
      
       bool Randomize();
      public:
       Demo();
       ~Demo();
      
       int GetSize( void );
       bool SetSize( int );
       double GetData( int );
       bool SetData( int , double );
      };
      
      bool Demo::Randomize( void )
      {
       for( int i=0; i < size ; i++ )
       {
        data[i] = (double) rand() / (double) RAND_MAX;
       }
       return true;
      }
      Here, randomize could only be called by the member functions of the class. (E.g., you could make SetData() an angry little function that scrambles the data every now and then.)

      Now that I think of it, it might not be a bad idea to pub ~Demo() in the private section, since you'd never want anybody to explicitly call ~Demo(). (Although I'm not sure if there would be other ramifications to this.)

      Interesting point you brought up. Thanks -- Paul

      Comment

      Working...