Hi,

I am trying to create a function pointer to std::endl

I get a compilation error in line number 36, where I am trying to assign the function pointer of std::endl to a pointer variable.

The compilation error states that ios_base constructor is private, but I am not trying to execute std::endl I am just assing the pointer value.


Pasted below is the code and compilation error:

Code:
/*

    Aim - To understand std :: endl

    std :: endl is actually a function

    
    template <class charT, class traits>
    basic_ostream<charT,traits>& endl ( basic_ostream<charT,traits>& os );

    template<
              class charT,
               class Traits = std::char_traits<charT>
            > class basic_ostream;


*/

#include <iostream>
#include <fstream>

int main()
{

    std :: ofstream fout;

    typedef std :: basic_ostream<std :: ofstream, std::char_traits<std :: ofstream> > BoType;

    std :: endl(fout);


    //Define function pointer type for std :: endl

    typedef BoType& (*EndlFunctType) (BoType&);

    EndlFunctType p1 = std :: endl;

    return(0);
}

Compilation error (I have pasted only the first few lines of the error):
Code:
/usr/include/c++/4.2.1/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/iosfwd:55:   instantiated from ‘std::basic_ostream<_CharT, _Traits>& std::endl(std::basic_ostream<_CharT, _Traits>&) [with _CharT = std::basic_ofstream<char, std::char_traits<char> >, _Traits = std::char_traits<std::basic_ofstream<char, std::char_traits<char> > >]’
test.cpp:36:   instantiated from here
/usr/include/c++/4.2.1/bits/ios_base.h:779: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/include/c++/4.2.1/iosfwd:55: error: within this context
/usr/include/c++/4.2.1/iosfwd: In copy constructor ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/iosfwd:92: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here 
/usr/include/c++/4.2.1/streambuf: In copy constructor ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’: