nvangogh <
nvan...@invalid.net> writes:
> On 12/04/13 18:04, nvangogh wrote:
> I have eliminated one of the big errors by making struct screen_size a
> base class:
>
> #ifndef SCREEN_H
> #define SCREEN_H
> #include <iostream>
> #include <string>
> #endif
>
> struct screen_size{
> int line_num;
> int column;
> };
The original posting had a missing ; here. There is no problem with
having this struct defined inside your class -- moving it outside does
not help except that you happened to add the missing semicolon.
> class Screen : public screen_size{
It does not make sense to derive Screen from screen_size *and* include
an object of type screen_size as a member. You are changing things
about to get rid of errors, but it's usually better to keep the code
unchanged until you *understand* the errors. You could have got the
original code (that looks sane to me) to compile if you'd left it alone
until you knew what the compiler was complaining about.
> Screen():defined_screen_size.line_num(0),
> defined_screen_size.column(0){}
You can't use . here. The way to do this is to reply on a constructor
for the member called defined_screen_size.
> Screen(int l, int
> c):defined_screen_size.line_num(l),defined_screen_size.column(c){}
>
> std::ostream& view_settings(std::ostream &os, const Screen &asc)
> {
> os << asc.defined_screen_size.line_num << " x " <<
> asc.defined_screen_size.column;
> return os;
> }
>
> // data members
> screen_size defined_screen_size;
> };
>
>
> This is the error outputs now:
>
>> Screen.h: In constructor ‘Screen::Screen()’:
>> Screen.h:14: error: expected ‘(’ before ‘.’ token
>> Screen.h:14: error: expected ‘{’ before ‘.’ token
>> Screen.h: In constructor ‘Screen::Screen(int, int)’:
>> Screen.h:15: error: expected ‘(’ before ‘.’ token
>> Screen.h:15: error: expected ‘{’ before ‘.’ token
As above.
>> Screen.h: In function ‘int main()’:
>> Screen.h:15: error: ‘Screen::Screen(int, int)’ is private
>> stest.cpp:7: error: within this context
>> Screen.h:18: error: ‘std::ostream& Screen::view_settings(std::ostream&, const Screen&)’ is private
>> stest.cpp:9: error: within this context
These are because you've made everything private (simply by having no
public: part of the class).
> -----------------------------------
>
> Looks like the way the constructors defined are the main problem now.
--
Ben.