The compiler do not recognize my function (newbie).

From: sphenxes (sphenxes_at_none.net)
Date: 12/05/04


Date: Sun, 05 Dec 2004 14:10:20 +0100


#include <iostream>
using namespace std;

class CatFive
{
private:
int itsAge;

public:
void hi(); //source of error
CatFive :: CatFive(int cage);
~CatFive();
void setData(int age);
int getData();
};

//////////////////////////

CatFive :: CatFive(int cage)
{
itsAge = cage;
}

CatFive :: ~CatFive()
{
}

void CatFive :: setData(int age)
{
itsAge = age;
}

int CatFive :: getData()
{
return itsAge;
}

void CatFive :: hi() //source of error
{
cout << " hi and welcome" << endl;
}

////////////////////////////////////
int main()
{
CatFive Frisky(1);

cout << " Frisky is " << Frisky.getData() << "years old" << endl;

Frisky.setData(3);
Frisky.getData(),

cout << Frisky.hi(); //source of error
cout << "Frisky is now " << Frisky.getData()<< "years old" << endl;

return 0;
}

Hi
I try to compile this program but I get a lot of errors because of
void hi(); function,
if I delete this function and all related data, the program is compiled
without any problems.
I am using g++ as a compiler (version 3.3.3) on linux Suse 9.1.
I have compiled similar programs several times before. I can't find the
error on my own.
Any sugession is appreciated.

Regards
Hesham Marei (sphenxes)

Compiler Errors
CatFive.cc:2: error: syntax error before `namespace'
CatFive.cc: In member function `void CatFive::hi()':
CatFive.cc:40: error: `cout' undeclared (first use this function)
CatFive.cc:40: error: (Each undeclared identifier is reported only once for
   each function it appears in.)
CatFive.cc:40: error: `endl' undeclared (first use this function)
CatFive.cc: In function `int main()':
CatFive.cc:54: error: `getData' undeclared (first use this function)
chat@linux:~/mydata/myprograms/c++/practice> g++ CatFive.cc -o CatFive
CatFive.cc:2: error: syntax error before `namespace'
CatFive.cc: In member function `void CatFive::hi()':
CatFive.cc:40: error: `cout' undeclared (first use this function)
CatFive.cc:40: error: (Each undeclared identifier is reported only once for
   each function it appears in.)
CatFive.cc:40: error: `endl' undeclared (first use this function)
CatFive.cc: In function `int main()':
CatFive.cc:54: error: `FriskyFrisky' undeclared (first use this function)
chat@linux:~/mydata/myprograms/c++/practice> g++ CatFive.cc -o CatFive
CatFive.cc: In function `int main()':
CatFive.cc:53: error: no match for 'operator<<' in 'std::cout <<
   (&Frisky)->CatFive::hi()'
/usr/include/g++/bits/ostream.tcc:63: error: candidates are:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ostream<_CharT,
   _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char,
   _Traits = std::char_traits<char>]
/usr/include/g++/bits/ostream.tcc:74: error:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::basic_ios<_CharT,
   _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
_Traits
   = std::char_traits<char>]
/usr/include/g++/bits/ostream.tcc:86: error:
   std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
   _Traits>::operator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT =
char,



Relevant Pages

  • Re: Passing an object pointer to function
    ... Just past the pointer created in the new call pRags without the '&'. ... > int GetAge() {return itsAge;} ... > void Function1; ...
    (microsoft.public.vc.language)
  • Re: Classes
    ... "Missing identifier before 'Cat' " should make you look carefully at what's ... > int getAge(); ... > void setAge; ... > int itsAge; ...
    (microsoft.public.vc.language)
  • Re: malloc problem
    ... is not what getData takes as a parameter. ... void getData(char **theData) { ... main*always* returns an int. ... void mainis wrong. ...
    (comp.lang.c)
  • Re: Classes
    ... Class Cat ... int getAge(); ... void setAge; ... itsAge = initialAge; ...
    (microsoft.public.vc.language)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)