std::unique_ptr with an incomplete type won’t compile

I’m using the pimpl-idiom with std::unique_ptr: class window { window(const rectangle& rect); private: class window_impl; // defined elsewhere std::unique_ptr<window_impl> impl_; // won’t compile }; However, I get a compile error regarding the use of an incomplete type, on line 304 in <memory>: Invalid application of ‘sizeof‘ to an incomplete type ‘uixx::window::window_impl‘ For as far as … Read more

C read file line by line

I wrote this function to read a line from a file: const char *readLine(FILE *file) { if (file == NULL) { printf(“Error: file pointer is null.”); exit(1); } int maximumLineLength = 128; char *lineBuffer = (char *)malloc(sizeof(char) * maximumLineLength); if (lineBuffer == NULL) { printf(“Error allocating memory for line buffer.”); exit(1); } char ch = … Read more