Zhilong Li 4 tahun lalu
induk
melakukan
0a1c6d8666
3 mengubah file dengan 40 tambahan dan 0 penghapusan
  1. 2 0
      CMakeLists.txt
  2. 19 0
      accumulator.cpp
  3. 19 0
      try_namespace.cpp

+ 2 - 0
CMakeLists.txt

@@ -15,4 +15,6 @@ add_executable(pointer_array pointer_array.cpp)
 add_executable(min_array min_array.cpp)
 add_executable(dyna_mem_array dyn_mem_array.cpp)
 add_executable(structures structures.cpp)
+add_executable(try_namespace try_namespace.cpp)
+add_executable(accumulator accumulator.cpp)
 target_link_libraries(CppYoutube functions)

+ 19 - 0
accumulator.cpp

@@ -0,0 +1,19 @@
+#include <iostream>
+#include <numeric>
+#include <string>
+
+int main()
+{
+    // This is a compiler feature
+    int testArr[140] = {[0 ... 139]=10};
+
+    printf("%lu\n", sizeof(testArr));
+
+    for (size_t i = 0; i <= 2; i++)
+    {
+        std::cout << testArr[i] << std::endl;
+    }
+    // the initial value must be float
+    float arrSum = std::accumulate(testArr, testArr + 140, 0.0);
+    std::cout << arrSum << std::endl;
+}

+ 19 - 0
try_namespace.cpp

@@ -0,0 +1,19 @@
+#include <iostream>
+
+namespace try1
+{
+    int what1 = 12;
+    float what2 = 23.33;
+}
+namespace try2
+{
+    int what1 = 13;
+    float what2 = 23.33;
+}
+
+
+int main()
+{
+    std::cout << try1::what1 << std::endl;
+    std::cout << try2::what1 << std::endl;
+}