为什么说next没有定义啊
#include<iostream>
using namespace std;
#include<string.h>
#define MAXLEN 255
typedef struct
{
char ch[MAXLEN+1];
int length;
} SString;
void StrAssign(SString &S,char s[])
{
S.length=strlen(s);
for(int i=1;i<=S.length;i++)
S.ch[i]=s[i-1];
}
int Index_BF(SString S, SString T,int pos)
{
int i,j;
i=pos; j=1;
while(i<=S.length && j<=T.length)
{
if(S.ch[i]==T.ch[j])
{
++i;
++j;
}
else
{
i=i-j+2;
j=1;
}
}
if(j>T.length)
return i-T.length;
else
return 0;
}
void StrPrint(SString S)
{
int i;
for(i=1;i<=S.length;i++)
cout<<S.ch[i];
cout<<endl;
}
void get_next(SString T,int next[])
{
int i,j;
i=1;
next[1]=0;
j=0;
while(i<T.length)
{
if(j==0||T.ch[i]==T.ch[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
void StrDelete(SString &S,SString T,int pos)
{
int i,j,k;
get_next(T,next);
for(i=pos;i<=S.length-T.length+1;i++)
{
k=Index_BF(S,T,i);
if(k)
{
for(j=k;j<=S.length-T.length;j++)
S.ch[j]=S.ch[j+T.length];
S.length=S.length-T.length ;
}
}
}
int main(){
SString S,T;
int k;
char string1[MAXLEN],string2[MAXLEN];
cout<<"输入主序列:";
gets(string1);
cout<<"输入子序列:";
gets(string2);
StrAssign(S,string1);
StrAssign(T,string2);
cout<<"输入起始位置:";
cin>>k;
StrDelete(S,T,k);
cout<<"删除后的主串为:";
StrPrint(S);
return 0;
}
68行 get_next(T,next);
是T.next,不是T,next,你把点写成了逗号
68行的next没定义,直接用了
你 StrDelete 里没有定义 next 吧?
访问限定符
C++实现封装的方式:用类将对象的属性与方法结合在一块,让对象更加完善,通过访问权限选 择性的将其接口提供给外部的用户使用。
【访问限定符说明】
1. public修饰的成员在类外可以直接被访问
2. protected和private修饰的成员在类外不能直接被访问(此处protected和private是类似的)
3. 访问权限作用域从该访问限定符出现的位置开始直到下一个访问限定符出现时为止
4. 如果后面没有访问限定符,作用域就到 } 即类结束。
5. class的默认访问权限为private,struct为public(因为struct要兼容C)
【注意】:访问限定符只在编译时有用,当数据映射到内存后,没有任何访问限定符上的区别