I wasn't sure what you meant by nested functions until I
found this wikipedia entry. It reminds me a lot of a "subfunction" 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:
-
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