15.0k views
1 vote
Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string 1 with the character string "ABCDEFGHI", what string does string 1( 4 , 2 ) return

a. "CDEF".
b. "CD".
c. "EFGHI".
d. "EF".

User Tom Leek
by
4.7k points

1 Answer

1 vote

Answer:

"EF"

Explanation:

Given

String1 = "ABCDEFGHI"

Substring : String1(4,2)

To solve this, one must understand the following

1. The function call operator () is used to overload objects of class type.

2. A copy constructor must receive its argument by reference to prevent an otherwise infinite recursion.

3. overload ( ), doesn't mean that one is not creating a new way to call a function; instead, it is a way to create an operator function that can be passed an arbitrary number of parameters

Having pointed out this,

The string to overload goes thus

String1 = "ABCDEFGHI"

The parameters goes thus

String1(4,2)

To represent this properly, we have

("ABCDEFGHI",4,2)

Which means to return 2 strings starting from the 4th index character.

It should be noted that index starts at 0.

So, the character at the 4th index is "E"

Then, we count 2 characters starting from E (i.e. E, inclusive)

This gives

"EF"

So, the returned string is "EF"

User Svein Bringsli
by
4.1k points