Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

basic_ofstream(const basic_ofstream&) = delete

49 views
Skip to first unread message

RM

unread,
Oct 6, 2020, 6:11:25 AM10/6/20
to
When trying to output xml_document of rapidxml library:

ofstream xml_file(xml_filepath.c_str());
print(xml_file, doc, 0);

I recive error:

src/cache.cpp: In function ‘void save_cache(std::__cxx11::string, const
char*, const char*, std::__cxx11::string, std::__cxx11::string,
std::__cxx11::string, bool&, const identifiers_vector (&)[5], const
std::unordered_map<std::__cxx11::basic_string<char>,
apostrophed_strings_map>*)’:
src/cache.cpp:204:27: error: use of deleted function
‘std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const
std::basic_ofstream<_CharT, _Traits>&) [with _CharT = char; _Traits =
std::char_traits<char>]’
print(xml_file, doc, 0);
^
In file included from src/cache.cpp:14:0:
/usr/include/c++/7/fstream:723:7: note: declared here
basic_ofstream(const basic_ofstream&) = delete;
^~~~~~~~~~~~~~

How can I solve the problem of deleted function?

Bonita Montero

unread,
Oct 6, 2020, 6:59:21 AM10/6/20
to
Define a proper print-function that takes a _reference_ to the stream.

Öö Tiib

unread,
Oct 6, 2020, 7:04:22 AM10/6/20
to
On Tuesday, 6 October 2020 13:11:25 UTC+3, RM wrote:
> When trying to output xml_document of rapidxml library:
>
> ofstream xml_file(xml_filepath.c_str());
> print(xml_file, doc, 0);

You post again what does not even compile? Your print function
is bad. This time about
some kind of library that probably hasn't been maintained for more
than 10 years?

> How can I solve the problem of deleted function?

Streams are not copyable so copy constructor is deleted. You solve
your problem with it by not attempting to copy streams.

Bonita Montero

unread,
Oct 6, 2020, 7:07:10 AM10/6/20
to
I'm wondering why he is dealing with such beyond-n00b-topics like
doing xml-processing and not even knowing how to define the print
function properly.

Öö Tiib

unread,
Oct 6, 2020, 7:51:01 AM10/6/20
to
I suspect that the reason is that there are not enough stand-alone
interesting novice programming missions but to do something actually
useful isn't easy.

For example try to communicate with some useful online service.
Those often reply to requests with xml, csv, yaml or json. Same
is with data or config files of some on-premise program. Such
are often whole compressed directories of huge structured text
files. For me it is piece of cake ... but for novice in world
full of various garbage libraries it is hilly territory.

James Kuyper

unread,
Oct 6, 2020, 12:10:50 PM10/6/20
to
From what you've told us so far, the only thing we can say is "don't do
that". It would be easier to provide a useful answer to that question if
you would provide the source code for save_cache() from src/cache.cpp.

Bonita Montero

unread,
Oct 6, 2020, 1:03:06 PM10/6/20
to
> From what you've told us so far, the only thing we can say is "don't do
> that". It would be easier to provide a useful answer to that question if
> you would provide the source code for save_cache() from src/cache.cpp.

Not necessary.
He is obviously passing an ofstream by value and not by referrence.

Juha Nieminen

unread,
Oct 7, 2020, 2:25:53 AM10/7/20
to
RM <robert_m...@wp.pl> wrote:
> When trying to output xml_document of rapidxml library:
>
> ofstream xml_file(xml_filepath.c_str());
> print(xml_file, doc, 0);
>
> I recive error:

We are supposed to guess how that print() function is declared?

Bonita Montero

unread,
Oct 7, 2020, 3:10:26 AM10/7/20
to
>> When trying to output xml_document of rapidxml library:
>>
>> ofstream xml_file(xml_filepath.c_str());
>> print(xml_file, doc, 0);
>>
>> I recive error:

> We are supposed to guess how that print() function is declared?

You don't have to know it exactly, but it takes a ofstream
-object without a reference for sure.

0 new messages