A
Art Werschulz
Hi.
I would like one of the constructors for a given class to take an
ostream as a parameter.
The following example (foo.cc) doesn't work:
---%<------%<------%<------%<--Cut-Here-%<------%<------%<------%<------
#include <iostream>
#include <string>
class X {
public:
X(std:stream os_param=std::cout): os(os_param) {}
void print(std::string s) { os << s; }
private:
std:stream os;
};
int main()
{
X x(std::cerr);
x.print("hello, world\n");
return 0;
}
---%<------%<------%<------%<--Cut-Here-%<------%<------%<------%<------
I get the following error msg (slightly reformatted to fit the line width):
foo.cc: In copy constructor `std::basic_ios<char,
std::char_traits<char> >::basic_ios(const std::basic_ios<char,
std::char_traits<char> >&)':
/usr/include/gcc/darwin/4.0/c++/bits/ios_base.h:736: error:
'std::ios_base::ios_base(const std::ios_base&)' is private
foo.cc:6: error: within this context
(Line 6 of foo.cc is the definition of the X constructor.)
Suggestions? Thanks.
I would like one of the constructors for a given class to take an
ostream as a parameter.
The following example (foo.cc) doesn't work:
---%<------%<------%<------%<--Cut-Here-%<------%<------%<------%<------
#include <iostream>
#include <string>
class X {
public:
X(std:stream os_param=std::cout): os(os_param) {}
void print(std::string s) { os << s; }
private:
std:stream os;
};
int main()
{
X x(std::cerr);
x.print("hello, world\n");
return 0;
}
---%<------%<------%<------%<--Cut-Here-%<------%<------%<------%<------
I get the following error msg (slightly reformatted to fit the line width):
foo.cc: In copy constructor `std::basic_ios<char,
std::char_traits<char> >::basic_ios(const std::basic_ios<char,
std::char_traits<char> >&)':
/usr/include/gcc/darwin/4.0/c++/bits/ios_base.h:736: error:
'std::ios_base::ios_base(const std::ios_base&)' is private
foo.cc:6: error: within this context
(Line 6 of foo.cc is the definition of the X constructor.)
Suggestions? Thanks.