S
subramanian100in
Kindly bear with me for this long post.
I have the following understanding about side-effects of a function.
Please correct me wherever I am wrong.
Suppose 'Test' is a user-defined type and 'testObj' is an instance of
'Test' class. If 'testObj' is a global object or a namespace-scope
object and if fn() is a function which modifies 'testObj', then fn()
is said to have side-effects. Also if fn() has 'testObj' as a local
static object and if fn() modifies this local static object, then also
fn() is said to have side-effects. If 'Test' class has a static data
member and if fn() modifies this static data member of 'Test' class,
then can fn() be said to have side-effects ?
Suppose
int var;
is a global variable or a namespace-scope variable or a local static
variable. Then if the function fn() modifies the variable 'var', then
can fn() be said to have side-effects ?
If a function modifies only automatic variables or automatic user-
defined-type objects, then the function does not have side-effects. Am
I correct ?
Can someone please explain the definition of side-effects, in simple
terms so that I can understand ?
If a function writes something to 'cout' object, why is it said that
the function has side-effects - what I am trying to ask is, in what
way 'cout' object is modified in order for the function to be said to
have side-efects ?
Thanks
V.Subramanian
I have the following understanding about side-effects of a function.
Please correct me wherever I am wrong.
Suppose 'Test' is a user-defined type and 'testObj' is an instance of
'Test' class. If 'testObj' is a global object or a namespace-scope
object and if fn() is a function which modifies 'testObj', then fn()
is said to have side-effects. Also if fn() has 'testObj' as a local
static object and if fn() modifies this local static object, then also
fn() is said to have side-effects. If 'Test' class has a static data
member and if fn() modifies this static data member of 'Test' class,
then can fn() be said to have side-effects ?
Suppose
int var;
is a global variable or a namespace-scope variable or a local static
variable. Then if the function fn() modifies the variable 'var', then
can fn() be said to have side-effects ?
If a function modifies only automatic variables or automatic user-
defined-type objects, then the function does not have side-effects. Am
I correct ?
Can someone please explain the definition of side-effects, in simple
terms so that I can understand ?
If a function writes something to 'cout' object, why is it said that
the function has side-effects - what I am trying to ask is, in what
way 'cout' object is modified in order for the function to be said to
have side-efects ?
Thanks
V.Subramanian