S
swhite
Hi,
Sorry, not very clear from the title but wasn't sure what to call it.
I was experimenting with the following in GCC 4.0.1 and didn't achieve
what I expected. I was trying to keep the internal class private, to
prevent creation, but also in the hope it might achieve something like
when you use "class <foo>;" to early declare to allow pointer passing,
but cannot access contents.
Also I passed out a const iterator containing this object expecting it
to make what it was iterating over const, but gcc allows me to change
it.
Just wondered what I should actually expect (found behaviour was
correct?) and anything close (if possible) to roughly achieve what I
was expecting.
#include <map>
#include <string>
class A
{
private:
struct Test
{
int a;
int b;
};
typedef std::map<std::string,Test *> Test2;
public:
typedef const Test2::const_iterator Test3;
private:
Test2 m_test;
public:
Test3 foo () { return m_test.end (); }
};
int main ()
{
A a;
A::Test3 test = a.foo ();
// Accesses object of private type...
// Didn't want, hoping for compiler error
int b = (*test).second->a;
(*test).second->a = 1; // modified const...
return 0;
}
Regards,
Simon
Sorry, not very clear from the title but wasn't sure what to call it.
I was experimenting with the following in GCC 4.0.1 and didn't achieve
what I expected. I was trying to keep the internal class private, to
prevent creation, but also in the hope it might achieve something like
when you use "class <foo>;" to early declare to allow pointer passing,
but cannot access contents.
Also I passed out a const iterator containing this object expecting it
to make what it was iterating over const, but gcc allows me to change
it.
Just wondered what I should actually expect (found behaviour was
correct?) and anything close (if possible) to roughly achieve what I
was expecting.
#include <map>
#include <string>
class A
{
private:
struct Test
{
int a;
int b;
};
typedef std::map<std::string,Test *> Test2;
public:
typedef const Test2::const_iterator Test3;
private:
Test2 m_test;
public:
Test3 foo () { return m_test.end (); }
};
int main ()
{
A a;
A::Test3 test = a.foo ();
// Accesses object of private type...
// Didn't want, hoping for compiler error
int b = (*test).second->a;
(*test).second->a = 1; // modified const...
return 0;
}
Regards,
Simon