MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Exercises/NoModules/Chapter 08/Soln8_04.cpp:9–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7std::string plus(const std::string& s1, const std::string& s2);
8
9int main()
10{
11 const int n {plus(3, 4)};
12 std::cout << "plus(3, 4) returns " << n << std::endl;
13
14 const double d {plus(3.2, 4.2)};
15 std::cout << "plus(3.2, 4.2) returns " << d << std::endl;
16
17 const std::string s {plus("he", "llo")};
18 std::cout << "plus(\"he\", \"llo\") returns " << s << std::endl;
19
20 const std::string s1 {"aaa"};
21 const std::string s2 {"bbb"};
22 const std::string s3 {plus(s1, s2)};
23 std::cout << "With s1 as " << s1 << " and s2 as " << s2 << std::endl;
24 std::cout << "plus(s1, s2) returns " << s3 << std::endl;
25
26 /*
27 const auto d {plus(3, 4.2)};
28 This won't compile because there is more than one overloaded plus() function for the arguments.
29 The compiler will not choose so there must be a unique match with a function signature.
30 */
31}
32
33// Adding integer values
34int plus(int a, int b)

Callers

nothing calls this directly

Calls 1

plusFunction · 0.70

Tested by

no test coverage detected