private within this context ... more

M

ma740988

I might be a little off topic but the experience level here is enough
to give me solid guidance.
So here's the code:

#ifndef FOO_TEST_H
#define FOO_TEST_H

#include <string>
#include <deque>
#include <iostream>
#include <sstream>
#include <typeinfo>
#include <cstddef>
#include <set>
#include <limits.h>

namespace foo {
class foo_test {
typedef std::deque< std::string > bucket;

bucket data;
bool bit;

void push_back ( std::string & str ) {
data.push_back( std::string() );
data.back().swap( str );
}

void mark ( void ) {
bit = true;
}

template < typename C, typename S >
struct io
{
static
foo_test & in ( foo_test & ft, S const & data )
{
std::stringstream in;
if ( in << data ) {
std::string str = in.str();
ft.push_back( str );
} else {
ft.mark();
}
return ( ft );
}
};

foo_test & operator<< ( int const & data ) {
return( io<void,int>::in( *this, data ) );
}

template < typename T >
static
void enlist ( std::string id = typeid(T).name() )
{
// stuff
}

public :
foo_test ()
: bit ( false ) {}
};
};

#endif

I'm _stuck with gcc 2.96_ for now. That said, the complaints when I
try to compile are as follows:

ccppc -g -mcpu=604 -mstrict-align -ansi -fno-builtin -I.
-IC:\Tornado2.2.1\target\h\ -DCPU
=PPC604 -DTOOL_FAMILY=gnu -DTOOL=gnu -c ..\main.cpp
In file included from ..\main.cpp:2:
...\fooTest.h: In function `static class foo::foo_test &
foo::foo_test::io<void,int>::in
(foo::foo_test &, const int &)':
...\fooTest.h:728: instantiated from here
...\fooTest.h:701: `void foo::foo_test::push_back(string &)' is private
...\fooTest.h:719: within this context
...\fooTest.h:706: `void foo::foo_test::mark()' is private
...\fooTest.h:721: within this context
...\fooTest.h:734: sorry, not implemented: `method_call_expr' not
supported by dump_expr
make: *** [main.o] Error 0x1

Done.

------------------------
offending line (1):
return( io<void,int>::in( *this, data ) );

The question: Why would the push_back and mark methods be considered
private 'in this context'?

The answer might be it's a gcc 2.96 bug but jsut wanting to ensure it's
not something I'm doing wrong.

offending line (2):
void enlist ( std::string id = typeid(T).name() )

I dont understand the 'method_call_expr' just yet but the error
"sorry, not implemented: `method_call_expr' not supported by dump_expr"
is also a mystery.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The work around:

1) add public before 'bucket data'.
public:
bucket data;


2)
template < typename T >
static
void enlist ( std::string id )
{
id = typeid(T).name();
// stuff
}

Workaround 2 I could live with. Workaround 1 bothers me. Ideas?

Thanks in advance
 
V

Victor Bazarov

ma740988 said:
I might be a little off topic but the experience level here is enough
to give me solid guidance.

Use other (newer) compilers to check your code when in doubt. It's not
a completely fool-proof method, but it often works well.
So here's the code:

#ifndef FOO_TEST_H
#define FOO_TEST_H

[...]
namespace foo {
[...]
};

The semicolon after the closing brace the defines the namespace
is the only violation of C++ rules in your code.
#endif

I'm _stuck with gcc 2.96_ for now. That said, the complaints [...]

The question: Why would the push_back and mark methods be considered
private 'in this context'?

You would have to ask g++ people.
The answer might be it's a gcc 2.96 bug but jsut wanting to ensure
it's not something I'm doing wrong.

You're not doing anything wrong *except* using a _very_old_ compiler.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top