【发布时间】:2014-03-29 07:41:50
【问题描述】:
水果.h
class Fruit
{
private:
std::int no[3];
public:
void initialize();
int print_type();
};
水果.cpp
#include "Fruit.h"
void Fruit::initialize() {
int no[] = {1, 2, 3};
}
int Fruit::print_type() {
return type[0];
}
Main.cpp
#include <iostream>
#include "Fruit.h"
using namespace std;
int main()
{
Fruit ff;
ff.initialize();
int output = ff.print_type();
cout << output;
system("pause");
return 0;
}
假设所需的指令包含在所有文件中。 此刻,我在取回输出时发现了一个问题,因为它不会导致“0”而是垃圾值。如何在不使用构造函数的情况下修复它?
真诚地希望有人能帮我一个忙。
【问题讨论】:
标签: arrays function private member