Function error

I will try to trim my code short. I am completely frustrated and can't seem to
fix my code. I been trying to solve this problem for 2 hours but I can't seem to
solve it.

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

class SpeechAnalyst
{
public:
int getNumberOfWords( ) const;
int getNumberOfSentences( ) const;
friend ostream& operator << ( ostream& outs, const SpeechAnalyst & sa );
};
int main ( )
{
some code;
}

int SpeechAnalyst::getNumberOfWords( ) const
{
// code that works
}

int SpeechAnalyst::getNumberOfSentences( ) const
{
//code that works
}

ostream& operator << ( ostream& outs, const SpeechAnalyst & sa )
{
int NumberofWords = getNumberOfWords( ); //Error
int NumberofSentences = getNumberOfSentences( ); //Error

}


My Errors
126 E:\C++ Assignment\SpeechAnalysis.cpp `getNumberOfWords' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
127 E:\C++ Assignment\SpeechAnalysis.cpp `getNumberOfSentences' undeclared (first use this function)
the functions getNumberOfWords and getNumberOfSentences are class methods, and therefore not in global scope. You need to use them as such.

1
2
3
4
5
ostream& operator << ( ostream& outs, const SpeechAnalyst & sa )
{
	int NumberofWords = sa.getNumberOfWords( );//calling sa's member function
	int NumberofSentences = sa.getNumberOfSentences( );//calling sa's member function
}
Last edited on
Thank you so much! It finally works!
Topic archived. No new replies allowed.