加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

C++中definition与declaration的区别

发布时间:2020-12-13 21:05:10 所属栏目:PHP教程 来源:网络整理
导读:翻了好几篇关于definition与declaration和博客,都写的很坑人 ,看来我得写1篇了,避免很多新手1入门就被坑了。 definition是通过 declaration 完全的定义了实体,每一个 declaration都是 definition,除下面几种情况。 1,存储类标识符extern开头的或语言连

翻了好几篇关于definition与declaration和博客,都写的很坑人 ,看来我得写1篇了,避免很多新手1入门就被坑了。

definition是通过declaration完全的定义了实体,每一个declaration都是definition,除下面几种情况。

1,存储类标识符extern开头的或语言连接标识符开头,但未初始化的。

extern const int a; // declares,but doesnt define a extern const int b = 1;// defines b
extern "C" void f1(void(*pf)()); // declares a function f1 with C linkage,



2.没有函数体的函数

int f(int); // declares,but doesnt define f



3.函数中未定义的参数

int f(int x); // declares,but doesnt define f and x int f(int x) { // defines f and x return x+a; }


4.类中声明的静态变量

struct S { // defines S int n; // defines S::n static int i; // declares,but doesnt define S::i }; int S::i; // defines S::i


5.只申明了类的名字,主要用在forward declaration和elaborated type中

struct S; // declares,but doesnt define S class Y f(class T p); // declares,but doesnt define Y and T (and also f and p)


6.模板参数

template<typename T> // declares,but doesnt define T


7.预先申明的模板

template<> struct A<int>; // declares,but doesnt define A


8.typedef声明

typedef S S2; // declares,but doesnt define S2 (S may be incomplete)


9.alias申明

using S2 = S; // declares,sans-serif;font-size:13px;line-height:15.360000610351563px;">10.模糊enum的申明

enum Color : int; // declares,but doesnt define Col


11.Using-declaration

using N::d; // declares,but doesnt define d




版权声明:本文为博主原创文章,未经博主允许不得转载。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读