I
ittium
Groups,
I have few doubts regarding argument type of function and types,
arguments can handle safely. I know these issues have been discussed at
multiple places on internet. I wanted to see the big picture and needed
opinion of C++ gurus
When you pass by value - Copy constructor is called (except for basic
data type like int, float). you can pass the **same type variable** only
When you pass by reference - A reference will be intialized with pass
value. you can pass **non-const same type or derived type** (passing a
constant type will return in error)
When you pass by constant reference you can pass **const/non-const of
same type or derived type**.
When you pass by pointer - pointer is assigned to passed value you can
pass **same type of derived type**.
Cases written above are safe conversion (no casting is needed). **C++
compiler will not allow any other conversion **. You can still use
casting for not allowed cases.
My doubts are
- Have I captured all the cases or there are some more cases (I will
appreciate a link to a small reference)
-What casts are safe e.g in case of pass by value casting from short to
int seems perfectly safe. (I will appreciate a link to any document
explaining safe casting)
thanks
Ittium
I have few doubts regarding argument type of function and types,
arguments can handle safely. I know these issues have been discussed at
multiple places on internet. I wanted to see the big picture and needed
opinion of C++ gurus
When you pass by value - Copy constructor is called (except for basic
data type like int, float). you can pass the **same type variable** only
When you pass by reference - A reference will be intialized with pass
value. you can pass **non-const same type or derived type** (passing a
constant type will return in error)
When you pass by constant reference you can pass **const/non-const of
same type or derived type**.
When you pass by pointer - pointer is assigned to passed value you can
pass **same type of derived type**.
Cases written above are safe conversion (no casting is needed). **C++
compiler will not allow any other conversion **. You can still use
casting for not allowed cases.
My doubts are
- Have I captured all the cases or there are some more cases (I will
appreciate a link to a small reference)
-What casts are safe e.g in case of pass by value casting from short to
int seems perfectly safe. (I will appreciate a link to any document
explaining safe casting)
thanks
Ittium