Re: The compiler do not recognize my function (newbie).

From: adbarnet (adbarnet_at_barnet.com)
Date: 12/05/04


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,
>



Relevant Pages

  • Re: pointer q
    ... int main (void) ... it would compile what you wanted was: ... a type compatible with the effective type of the object, ...
    (comp.lang.c)
  • Re: compiling error
    ... How to make it compile? ... void open_file ... int buf; ... Okay arrays when passed to function should not have the index but the ...
    (comp.lang.c)
  • Re: Writing to text segment
    ... memcpy((void *)&foo, buf, sizeof buf); ... Because it won't compile? ... volatile int i = 1; ...
    (comp.lang.c)
  • Please Help => Simple Program
    ... I am trying to compile a Visual Studio 2005 C++ project using an ... about converting from void* to float* because of the last 5 parameters ... in the "BiquadSections" structure. ... int main ...
    (microsoft.public.dotnet.languages.vc)
  • SUMMARY: void main(int argc, char *argv[]) question
    ... The consensus is that the use of void on main is wrong (The book ... return and int. ... >In trying to compile some old test Unix C programs... ... Why do those old UNIX programs used void ... ...
    (SunManagers)