簡體   English   中英

在C ++函數簽名中使用struct是否定義明確?

[英]Is the use of `struct` well-defined in c++ function signatures?

這個問題與另一個問題類似,但比另一個問題更具體:

在C ++中的變量聲明中使用struct關鍵字

考慮以下程序:

#include <stdio.h>

struct Foo {
    int x;
    int y;
};

Foo getFoo() {
    Foo foo;
    return foo;
}

int main(){
    getFoo();
}

上面的程序使用g++編譯,但不能使用gcc

我們可以按以下方式修改程序,使其可以同時使用gccg++進行編譯:

#include <stdio.h>

struct Foo {
    int x;
    int y;
};

struct Foo getFoo() {
    struct Foo foo;
    return foo;
}

int main(){
    getFoo();
}

標准是否保證使用struct關鍵字在C ++中定義良好

是。 這被稱為詳細類型說明符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM