类与结构体

1. 区别与应用

 

2. 示例

struct A{};
class B : A{};//private继承
struct C : B{}; //public继承
struct A//定义一个struct
{
char c1;
int n2;
double db3;
}; 
A a={'p',7,3.1415926}; //定义时直接赋值 可行
class A//定义一个struct
{
char c1;
int n2;
double db3;
};
A a={'p',7,3.1415926}; //定义时直接赋值  会报错!!!,因为class内默认访问属性为private
复制代码
template <class T>\\正确
struct Person
{
public:
    T age;
};



template <typename T>\\正确
struct Person
{
public:
    T age;
};



template <struct T>\\错误
struct Person
{
public:
    T age;
};
复制代码

3. 引用:https://javaforall.cn/228006.html   原文链接:https://javaforall.cn.

posted @   二先生-  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示