On 09/04/2013 14:52, nvangogh wrote:
>
> I am having problems compiling a simple user defined class, with a
> constructor that takes an istream argument. I am trying to test this
> constructor. The other three constructors work.
>
> The problem is not with the istream. I cannot see how it can be with the
> read function either as I have tested it with other options.
>
> If I try to compile with a main program , i get this error:
>
> 'g++ cons4.cpp -o cons4
> In file included from cons4.cpp:4:
> Sales_data.h: In constructor ‘Sales_data::Sales_data(std::istream&)’:
> Sales_data.h:32: error: invalid conversion from ‘void*’ to ‘int’
> Sales_data.h:32: error: cannot convert ‘Sales_data’ to ‘void*’ for
> argument ‘2’ to ‘ssize_t read(int, void*, size_t)’
There is the clue, it has found another overload of read(). At this
stage in your code I cannot see a declaration of the read you want to use.
Of course, the read (as should the print) in question should be a member
function and as such will only have a single parameter, an istream&.
Whilst definitions can be delayed, declarations must be nm
made before something is first used.
In general C++ does not allow the implementation to look ahead for a
declaration. Unlike the earlier versions of C which allowed implicit
declarations of functions C++ has never allowed that (almost impossible
to support in the context of overloading)
Francis