
ZCL_ART_BITMAP
.METHOD trace_ray.
DATA(shade_rec) = _world->hit_bare_bones_objects( i_ray ).
IF shade_rec->hit_an_object = abap_true.
r_color = shade_rec->color.
ELSE.
r_color = zcl_art_rgb_color=>new_copy( me->_world->background_color ).
ENDIF.
ENDMETHOD.
hit_bare_bones_objects
method inside the class zcl_art_world
:METHOD hit_bare_bones_objects.
DATA:
t TYPE decfloat16,
tmin TYPE decfloat16 VALUE '10000000000'.
r_shade_rec = zcl_art_shade_rec=>new_from_world( me ).
LOOP AT _objects ASSIGNING FIELD-SYMBOL(<object>).
<object>->hit(
EXPORTING
i_ray = i_ray
IMPORTING
e_tmin = t
e_hit = DATA(hit)
CHANGING
c_shade_rec = r_shade_rec ).
IF hit = abap_true AND ( t < tmin ).
r_shade_rec->hit_an_object = abap_true.
tmin = t.
r_shade_rec->color = <object>->get_color( ).
ENDIF.
ENDLOOP.
ENDMETHOD.
shade_rec
).IMPORTING
, EXPORTING
and so forth describe the role and changeability of a parameter passed to and used by a method. These keywords are often not as explicitly articulated in other programming languages.Input | Output | Input-Output | |
IMPORTING | X | ||
EXPORTING | X | ||
CHANGING | X | ||
RETURNING | X |
VALUE(...)
and by REFERENCE(...)
.VALUE(...)
instead of REFERENCE(...)
.IMPORTING
, ...)Pass-By-Value | Pass-By-Reference (&) | Pass-By-Pointer (*) | |
IMPORTING | VALUE(...) (possible for simple types, with helper functionality) | REFERENCE(...) | REFERENCE(...) |
EXPORTING | - | REFERENCE(...) | REFERENCE(...) |
CHANGING | - | REFERENCE(...) | REFERENCE(...) |
RETURNING | VALUE(...) | - | - |
const
is a keyword which tells the compiler, that the parameter cannot be changed - is constant.const
.const
, but that is not enforced by C++.void
keyword lets you instantly know, that this method doesn't have a returning parameter in stock.void
is specified before the method name, I have my return type and know that a returning value is needed.//None
void foobar();
//Value
int foobar();
//Reference
int& foobar();
//Pointer
int* foobar();
Code examples: void, value, reference, pointer
"None
METHODS foobar.
"Value
METHODS foobar
RETURNING
VALUE(r_result) TYPE int4.
"Reference
METHODS foobar
RETURNING
VALUE(r_result) TYPE REF TO int4.
"Pointer
"Doesn't exist in ABAP.
"Same approach like Reference taken, with 'TYPE REF TO'
Code examples: void, value, reference
const
in the signature is an explicit indicator, that the parameter is an importing parameter. Cause in C++ the keyword const
guarantees that the parameter cannot be altered by the method.const
, the parameter might be an importing one.//Pass-By-Value
void foobar(const int value);
//Pass-By-Reference
void foobar(const int& value);
//Pass-By-Pointer
void foobar(const int* value);
Code examples: value, reference, pointer
"Pass-By-Value
METHODS foobar
IMPORTING
VALUE(i_value) TYPE int4.
"Pass-By-Reference
METHODS foobar
IMPORTING
REFERENCE(i_value) TYPE int4.
"Pass-By-Pointer
"Doesn't exist in ABAP. Same approach like Pass-By-Reference taken.
Code examples: value, reference
const
can be an exporting parameter, but you need to check inside the method, whether more than assignment is going on in there.//Pass-By-Value
//Cannot be used, as the change would be lost when returned to the caller.
//Pass-By-Reference
void foobar(int& value);
//Pass-By-Pointer
void foobar(int* value);
Code examples: reference, pointer
"Pass-By-Value
METHODS foobar
EXPORTING
VALUE(e_value) TYPE int4.
"Pass-By-Reference
METHODS foobar
EXPORTING
REFERENCE(e_value) TYPE int4.
"Pass-By-Pointer
"Doesn't exist in ABAP. Same approach like Pass-By-Reference taken.
Code examples: value, reference
//Pass-By-Value
//Cannot be used, as the change would be lost when returned to the caller.
//Pass-By-Reference
void foobar(int& value);
//Pass-By-Pointer
void foobar(int* value);
Code examples: reference, pointer
"Pass-By-Value
METHODS foobar
CHANGING
VALUE(c_value) TYPE int4.
"Pass-By-Reference
METHODS foobar
CHANGING
REFERENCE(c_value) TYPE int4.
"Pass-By-Pointer
"Doesn't exist in ABAP. Same approach like Pass-By-Reference taken.
Code examples: value, reference
When plotting this blog, I found very confusing to view the pass-by types and parameter types in conjunction. Especially, the pass-by-value of a parameter which refers to a class.
class Foo {
public:
void foobar(const Bar value);
};
void Foo::foobar(const Bar value) {
std::cout << value.getValue();
}
The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously.
Tutorials Point, "C++ Copy Constructor", Accessed 21.10.2017
CLASS cl_foo DEFINITION.
PUBLIC SECTION.
METHODS:
pass_class_by_reference
IMPORTING
REFERENCE(i_value) TYPE REF TO cl_bar,
pass_class_by_value
IMPORTING
VALUE(i_value) TYPE REF TO cl_bar.
ENDCLASS.
Please right click on the following screenshots and
choose "Open image in new tab" to see them in appropriate size.
Pass-By-Reference | |
![]() | ![]() |
160 Bytes | 352 Bytes |
Pass-By-Value | |
![]() | ![]() |
160 Bytes | 368 Bytes |
zcl_art_geometric_object
.zcl_art_multiple_objects
).You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |