Arduino如何使函数返回固定大小的数组

时间:2019-12-17 13:16:17

标签: c++ arrays function arduino

我正在尝试创建返回数组的函数,但是在使用时

<p-table [resizableColumns]="'false'" *ngIf="groupKey" class="png-table" [value]="data" [dataKey]="groupKey" scrollHeight="500px"
[scrollable]="'true'" [columns]="cols">
<ng-template pTemplate="colgroup" let-columns>
    <colgroup>
        <ng-container *ngFor="let col of columns">
            <col *ngIf="!col.hide" [style.width.px]="col.width">
        </ng-container>

    </colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
    <tr>
        <ng-container *ngFor="let col of columns">
            <th [pSortableColumn]="col.field" *ngIf="!col.hide" pResizableColumn pReorderableColumn [class]="col.filter?'sortable':'non-sortable'">
                {{col.headerName}}
                <p-sortIcon [field]="col.field"></p-sortIcon>
            </th>
        </ng-container>
    </tr>
    <!-- <tr class="filter-row">
        <th *ngFor="let col of columns" [hidden]="col.hide">
            <input class="filter-input" *ngIf="col.filter" pInputText type="text" (input)="dt.filter($event.target.value, col.field, 'contains')">
        </th>
    </tr> -->
</ng-template>
<ng-template pTemplate="body" let-rowData let-rowIndex="rowIndex" let-expanded="expanded" let-columns="columns">
    <tr class="ui-widget-header" *ngIf="rowGroupMetadata[rowData[groupKey]].index === rowIndex">
        <td colspan="7">
            <a href="#" [pRowToggler]="rowData">
                <i [ngClass]="expanded ? 'fa fa-fw fa-chevron-circle-down' : 'fa fa-fw fa-chevron-circle-right'"></i>
                <span>{{rowData[groupKey]}}</span>
            </a>
        </td>
    </tr>
</ng-template>
<ng-template pTemplate="rowexpansion" let-rowData let-rowIndex="rowIndex" let-columns="columns">
    <tr>
        <ng-container *ngFor="let col of columns" [ngSwitch]="col.type">
            <td classs="ui-resizable-column" *ngSwitchCase="'del'" [ngStyle]="getHeaderStyle(col)">
                <i class="fa fa-close delete-icon g-act-icon" (click)='deleteRow()'></i>
            </td>
            <td classs="ui-resizable-column" *ngSwitchCase="'edit'" [ngStyle]="getHeaderStyle(col)">
                <i class="fa fa-edit edit-icon g-act-icon" (click)='deleteRow()'></i>
            </td>
            <td classs="ui-resizable-column" *ngIf="!col.hide && col.type=='type'" [ngStyle]="getHeaderStyle(col)">
                {{rowData[col.field]}}
            </td>
            <td classs="ui-resizable-column" [pEditableColumn] *ngSwitchCase="'cep'" [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <p-inputMask (keyup)="onEnterCEP()" mask="aaaaaa-999-999"></p-inputMask>

                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td classs="ui-resizable-column" [hidden]="col.hide" *ngSwitchCase="'cb'" [ngStyle]="getHeaderStyle(col)">
                {{rowData[col.field]}}
            </td>
            <td classs="ui-resizable-column" [pEditableColumn] *ngIf="!col.hide && col.type=='act'" [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td classs="ui-resizable-column" *ngIf="!col.hide && col.type=='com'" [pEditableColumn] [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td classs="ui-resizable-column" [pEditableColumn] *ngIf="!col.hide && col.type=='tsk'" [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td classs="ui-resizable-column" *ngIf="!col.hide && col.type=='sco'" [pEditableColumn] [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td classs="ui-resizable-column" [pEditableColumn] *ngIf="!col.hide && col.type=='hrs'" [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>
            <td  classs="ui-resizable-column" *ngIf="!col.hide && col.type=='des'" [pEditableColumn] [ngStyle]="getHeaderStyle(col)">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
                    </ng-template>
                    <ng-template pTemplate="output">
                        {{rowData[col.field]}}
                    </ng-template>
                </p-cellEditor>
            </td>

        </ng-container>
    </tr>
</ng-template>

我得到:将'int *'分配给'int [5]'的类型不兼容

1 个答案:

答案 0 :(得分:0)

您的Arduino-IDE可能不支持C ++的std::array,如注释中所述,但是您可以这样做:

int* get() {
    static int my_array[] = {1, 1, 1, 1, 1};
    return my_array;
}

无法像在setup函数中尝试过的那样重新分配数组。

考虑使用:

int* x = nullptr;

void setup() {
    x = get();
}

我必须指出,这不是最佳实践。也许您可以提供更多信息以找到更好的解决方案。