求字符串长出问题了(共和国的高手快来支援!!!)

来源:百度知道 编辑:UC知道 时间:2024/09/22 01:02:08
#include<iostream>
#include<string>
using namespace std;

class zfc
{
char st;
int i;
int len;
public:
zfc(char str5);
01 int my_strlen(st);
void dis() //输出串长
{
cout<<len<<endl;
}

};

zfc::zfc(char str5)
{
st=str5;
02 my_strlen(st);

}

03 int zfc::my_strlen(st) //求串长
04 {

while(st[len]!='\0')
len++;
return len;
}

void main()
{
char str1[]="hello there";
zfc a();

}
毛病如下:
标号01处 syntax error:identifier 'st'
标号02处 my_strlen:function does not take 1 paramemeters
标号03处 illegal reference to data member 'zfc::st'in a static membir funciton
标号04处 〈unknown〉function-style initializer appears to be a function definition
还有下面

01,03处错误:既然是函数声明,形参的数据类型就要写。
解决了这两个就剩一个错误了,就是你讲的subscript requires array pointer type 的错误,位置在04的下面一行。意思是说只有数组才可以使用下标。也就是说st没有被定义成数组。