C++中类的私有成员变量中有一个结构体数组,请教怎么调用并返回
C++中类的私有成员变量中有一个结构体数组,请问如何调用并返回?
struct str
{
string a;
string b;
};
class B
{
private:
int a;
str s[10];
public:
str* gets()const{ return s; }
}
请问如何返回这个s[10]数组呢,貌似我的那个gets()函数会出错?
------解决方案--------------------
你是const函数,返回内部指针会出错的,
const str* gets()const{ return s; }
or
str* gets(){ return s; }
struct str
{
string a;
string b;
};
class B
{
private:
int a;
str s[10];
public:
str* gets()const{ return s; }
}
请问如何返回这个s[10]数组呢,貌似我的那个gets()函数会出错?
------解决方案--------------------
你是const函数,返回内部指针会出错的,
const str* gets()const{ return s; }
or
str* gets(){ return s; }