首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >出现了C++ C26495警告,但我不知道如何解决

出现了C++ C26495警告,但我不知道如何解决
EN

Stack Overflow用户
提问于 2021-07-11 06:15:26
回答 1查看 951关注 0票数 0

这是我的代码:

代码语言:javascript
运行
复制
#pragma once

#include "Card.h"

class Foundation {

    Card* cards[13];
    int current;
    char suit;
    friend ostream& operator<< (ostream& os, Foundation& f);
public:

    Foundation(char suit = 'H');
    bool isPlacable(Card* c);
    void put(Card* c);
    bool isFull();
    void clear();
};

/* Warning  C26495  Variable 'Foundation::cards' is uninitialized. Always initialize a member variable (type.6) below. */

Foundation::Foundation(char suit) {

    this->suit = suit;
}

有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-11 06:26:46

您会得到警告,因为您没有初始化构造函数中的成员或使用初始化程序列表。

这可能会修正您的警告:

代码语言:javascript
运行
复制
class Foundation {

    Card* cards[13] = {};
    int current;
    char suit;
    friend ostream& operator<< (ostream& os, Foundation& f);
public:

    Foundation(char suit = 'H');
    bool isPlacable(Card* c);
    void put(Card* c);
    bool isFull();
    void clear();
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68333673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档