error with friendly function
Apr 20, 2020 at 7:06am UTC
Hey, i cant understand the mistake im doing. void lyg is my friend function, and i dont know how to access ny symbol function there. i get error that no matching function to call for Tekstas::symbol in line 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
int symbol(){
int a=0;
for (int i=0; i<n; i++){
for (int j=0; j<s[i].size(); j++){
a=0;
while (isalpha(s[i][j])){
j++;
a++;
}cout<<i+1<<" " <<a<<endl;
}
}
return a;
}
};
void lyg(Tekstas T){
for (int i=0; i<=T.n; i++){
cout<<i<<endl;
if (T.symbol(T.s[i]) %2==0){
cout << T.s[i] << " " << T.symbol(T.s[i]) << endl;
}
}
Last edited on Apr 20, 2020 at 7:06am UTC
Apr 20, 2020 at 7:23am UTC
The function symbol()
does not expect any paramter. on line 21/22 you pass T.s[i]
to that function, which is not correct.
Apr 20, 2020 at 7:31am UTC
after fixing this, same error. i need my void to detect of the certain word from words array has even number of letters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
int symboliai(string word[]){
int a=0;
for (int i=0; i<n; i++){
for (int j=0; j<word[i].size(); j++){
a=0;
while (isalpha(word[i][j])){
j++;
a++;
}//cout<<i+1<<" "<<a<<endl;
}
}
return a;
}
};
void lyginiai(Tekstas T){
for (int i=0; i<=T.n; i++){
//cout<<i<<endl;
if (T.symboliai(T.s[i]) %2==0){
cout << T.s[i] << " " << T.symboliai(T.s[i]) << endl;
}
}}
Apr 20, 2020 at 7:51am UTC
I don't know what
s
is but i would think it is an array of strings. Then
T.s[i]
is passing just a single string while now
symboliai(string word[])
expects an array.
But you do not need to pass
s
at alll since symboliai(...) as a part of the class knows
s
. Hence you just need to pass the index:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
int symboliai(int i string word[]){
int a=0;
for (int i=0; i<n; i++){
for (int j=0; j< s word[i].size(); j++){
a=0;
while (isalpha(s word[i][j])){
j++;
a++;
}//cout<<i+1<<" "<<a<<endl;
}
}
return a;
}
};
void lyginiai(Tekstas T){
for (int i=0; i<=T.n; i++){
//cout<<i<<endl;
if (T.symboliai(i T.s[i]) %2==0){
cout << T.s[i] << " " << T.symboliai(i T.s[i]) << endl;
}
}}
By the way: Neither line 5 nor 7 seems to be correct.
Topic archived. No new replies allowed.