Re: The compiler do not recognize my function (newbie).
From: adbarnet (adbarnet_at_barnet.com)
Date: 12/05/04
- Next message: Bob Hairgrove: "Re: borland vs. microsoft"
- Previous message: Anton Lauridsen: "Re: almost newbie like question regarding type conversion"
- In reply to: sphenxes: "The compiler do not recognize my function (newbie)."
- Next in thread: sphenxes: "Re: The compiler do not recognize my function (newbie)."
- Reply: sphenxes: "Re: The compiler do not recognize my function (newbie)."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 5 Dec 2004 14:06:28 -0000
It appears you are not 'using' namespace std on you cout and endl's try
std::cout and std::endl - or using namespace statement (not recomended if
you are including the cc file with your header).
ad
"sphenxes" <sphenxes@none.net> wrote in message
news:1102252197.ZrqGIQcJbmvbKGFCyg48kw@teranews...
> #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,
>
- Next message: Bob Hairgrove: "Re: borland vs. microsoft"
- Previous message: Anton Lauridsen: "Re: almost newbie like question regarding type conversion"
- In reply to: sphenxes: "The compiler do not recognize my function (newbie)."
- Next in thread: sphenxes: "Re: The compiler do not recognize my function (newbie)."
- Reply: sphenxes: "Re: The compiler do not recognize my function (newbie)."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|