いろいろなテクニック.Nucleo と DISCO-F746 用.

Dependencies:   Array_Matrix mbed

Revision:
0:bb939e0bc6e2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CompoundLiteral.hpp	Sun Oct 15 11:41:48 2017 +0000
@@ -0,0 +1,30 @@
+//---------------------------------------
+//  複合リテラルの例
+//---------------------------------------
+
+void CompoundLiteral()
+{
+    // 配列の場合
+    printf("\r\n配列の場合:\r\n");  
+    Array<int> xInt(3, (int[]){ 2, 8, -5}); // ここで複合リテラルを使用
+    for (int n=0; n<xInt.Length(); n++)
+        printf("xInt[%d] = %d\r\n", n, xInt[n]);
+
+    xInt.Assign((int[]){ -1, 2, -3});       // ここで複合リテラルを使用
+    printf("\r\n");
+    for (int n=0; n<xInt.Length(); n++)
+        printf("xInt[%d] = %d\r\n", n, xInt[n]);
+
+    Array<string> str(2, (string[]){"ABC", "DEFG"});    // ここで複合リテラルを使用
+    printf("\r\n");
+    for (int n=0; n<str.Length(); n++)
+        printf("str[%d] = %s\r\n", n, str[n].c_str());
+
+    // 構造体の場合
+    struct struct1 { int x1; float x2; string str; };
+    struct1 data1 = (struct1){ 8, 0.2f, "abc"}; // ここで複合リテラルを使用
+    printf("\r\n構造体の場合:\r\n");
+    printf("x1:  %d\r\n", data1.x1);
+    printf("x2:  %f\r\n", data1.x2);
+    printf("str: %s\r\n", data1.str.c_str());
+}