S
sphenxes
#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>:
perator<<(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>:
perator<<(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>:
perator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT =
char,
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>:
_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>:
_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>:
char,