A
Adrian
Hi Guys,
I obviously have a mistake in this - I just cant seem to see it for
looking this morning.
I've tried various forms of the friend declaration but the compiler
seems to be ignoring them all.
Why wont the following compile when using namespaces
TIA
Adrian
adrianc@dluadrianc:~> g++ -Wall -ansi -pedantic -Wextra -Weffc++ foo.cc
foo.cc:18:12: warning: unused parameter 'os'
foo.cc:32:5: warning: unused parameter 'argc'
foo.cc:32:5: warning: unused parameter 'argv'
adrianc@dluadrianc:~> g++ -DNAMESPACES -Wall -ansi -pedantic -Wextra
-Weffc++ foo.cc
foo.cc:18:12: warning: unused parameter 'os'
foo.cc:32:5: warning: unused parameter 'argc'
foo.cc:32:5: warning: unused parameter 'argv'
foo.cc: In function 'std:stream& operator<<(std:stream&, const
level1::level2::foo&)':
foo.cc:18:12: error: 'void level1::level2::foo:rint(std:stream&)
const' is private
foo.cc:43:16: error: within this context
#include <iostream>
#ifdef NAMESPACES
namespace level1
{
namespace level2
{
#endif
class foo
{
public:
#ifdef NAMESPACES
friend std:stream &operator<<(std:stream &os, const
::level1::level2::foo &rhs);
#else
friend std:stream &operator<<(std:stream &os, const foo &rhs);
#endif
private:
void print(std:stream &os) const
{
}
};
#ifdef NAMESPACES
}}
#endif
#ifdef NAMESPACES
std:stream &operator<<(std:stream &os, const level1::level2::foo &rhs);
#else
std:stream &operator<<(std:stream &os, const foo &rhs);
#endif
int main(int argc, char *argv[])
{
return 0;
}
#ifdef NAMESPACES
std:stream &operator<<(std:stream &os, const level1::level2::foo &rhs)
#else
std:stream &operator<<(std:stream &os, const foo &rhs)
#endif
{
rhs.print(os);
return os;
}
I obviously have a mistake in this - I just cant seem to see it for
looking this morning.
I've tried various forms of the friend declaration but the compiler
seems to be ignoring them all.
Why wont the following compile when using namespaces
TIA
Adrian
adrianc@dluadrianc:~> g++ -Wall -ansi -pedantic -Wextra -Weffc++ foo.cc
foo.cc:18:12: warning: unused parameter 'os'
foo.cc:32:5: warning: unused parameter 'argc'
foo.cc:32:5: warning: unused parameter 'argv'
adrianc@dluadrianc:~> g++ -DNAMESPACES -Wall -ansi -pedantic -Wextra
-Weffc++ foo.cc
foo.cc:18:12: warning: unused parameter 'os'
foo.cc:32:5: warning: unused parameter 'argc'
foo.cc:32:5: warning: unused parameter 'argv'
foo.cc: In function 'std:stream& operator<<(std:stream&, const
level1::level2::foo&)':
foo.cc:18:12: error: 'void level1::level2::foo:rint(std:stream&)
const' is private
foo.cc:43:16: error: within this context
#include <iostream>
#ifdef NAMESPACES
namespace level1
{
namespace level2
{
#endif
class foo
{
public:
#ifdef NAMESPACES
friend std:stream &operator<<(std:stream &os, const
::level1::level2::foo &rhs);
#else
friend std:stream &operator<<(std:stream &os, const foo &rhs);
#endif
private:
void print(std:stream &os) const
{
}
};
#ifdef NAMESPACES
}}
#endif
#ifdef NAMESPACES
std:stream &operator<<(std:stream &os, const level1::level2::foo &rhs);
#else
std:stream &operator<<(std:stream &os, const foo &rhs);
#endif
int main(int argc, char *argv[])
{
return 0;
}
#ifdef NAMESPACES
std:stream &operator<<(std:stream &os, const level1::level2::foo &rhs)
#else
std:stream &operator<<(std:stream &os, const foo &rhs)
#endif
{
rhs.print(os);
return os;
}