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

c – 功能无法访问

发布时间:2020-12-16 10:54:59 所属栏目:百科 来源:网络整理
导读:我有 // file BoardInitializer.h#include stdio.h#include tchar.h#include string#include iostreamusing namespace std;class BoardInitializer{ static int *beginBoard; static int *testBoard; static void testBoardInitialize();}// file mh.cpp#inc
我有

// file BoardInitializer.h
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>

using namespace std;
class BoardInitializer
{
    static int *beginBoard;
    static int *testBoard;
    static void testBoardInitialize();
}



// file mh.cpp
#include "BoardInitializer.h"

int main(int argc,char* argv[])
{
    BoardInitializer.testBoardInitialize();
    return 0;
}

我在mh.cpp中实现了BoardInitializer :: testBoardInitialize.
但我收到错误“功能无法访问”.怎么了?

解决方法

C中类的默认保护级别是私有的(带有
其他人是公开的和受保护的).这意味着你所有的
成员和您的成员函数是私有的,只能通过
该类或朋友的其他成员函数(函数或类)
那个班.

函数main既不是,你最终得到错误.

C提供了一个方便的快捷方式(或C传统的cruft,取决于你的
worldview)名为struct,默认保护级别为
上市.

class my_class {
public:
  int my_int;      
};

要么

struct my_struct {
  int my_int;
};

应该显示出差异.

(编辑:李大同)

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

    推荐文章
      热点阅读