T
Thomas
Hi everybody!
I have the following code:
---snip---
class BaseRecord
{
protected:
struct tFieldLenData
{
std:stream &print(ostream &os) const
{
os << " name = " <<_name << endl;
return os:
}
// ... do anything ...
string _name;
};
public:
// ... do anything ...
};
std:stream &
operator << (std:stream &os,
BaseRecord const &rec);
std:stream &
operator << (std:stream &os,
BaseRecord::tFieldLenData const &fd);
---snap---
From gcc-2.96 upwards I always get the following error message:
In function `ostream &operator<< (ostream &, const
BaseRecord::tFieldLenData &)':
struct BaseRecord::tFieldLenData is protected
I'm confused about this error, because even the type is declared as
protected, I expect it to be usable as type within a typedef or
function declaration outside the scope of it's outer class.
The fact, that an object of type tFieldLenData cannot be instantiated
outside the class BaseRecord is clear, but this should not care the
compiler in this case.
My idea is, to have the possibilty to print the object to stdout or
stderr from within the class itself, for instance for debugging
purpose.
I now have two questions concerning this point:
1.) Is this error message appropriate ?
2.) If you say yes to no. 1, then what would be a nicer solution for
this case in your opinion ?
kind regards,
Thomas
I have the following code:
---snip---
class BaseRecord
{
protected:
struct tFieldLenData
{
std:stream &print(ostream &os) const
{
os << " name = " <<_name << endl;
return os:
}
// ... do anything ...
string _name;
};
public:
// ... do anything ...
};
std:stream &
operator << (std:stream &os,
BaseRecord const &rec);
std:stream &
operator << (std:stream &os,
BaseRecord::tFieldLenData const &fd);
---snap---
From gcc-2.96 upwards I always get the following error message:
In function `ostream &operator<< (ostream &, const
BaseRecord::tFieldLenData &)':
struct BaseRecord::tFieldLenData is protected
I'm confused about this error, because even the type is declared as
protected, I expect it to be usable as type within a typedef or
function declaration outside the scope of it's outer class.
The fact, that an object of type tFieldLenData cannot be instantiated
outside the class BaseRecord is clear, but this should not care the
compiler in this case.
My idea is, to have the possibilty to print the object to stdout or
stderr from within the class itself, for instance for debugging
purpose.
I now have two questions concerning this point:
1.) Is this error message appropriate ?
2.) If you say yes to no. 1, then what would be a nicer solution for
this case in your opinion ?
kind regards,
Thomas