• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Friend error with gcc 4.0 in Xcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Friend error with gcc 4.0 in Xcode


  • Subject: Re: Friend error with gcc 4.0 in Xcode
  • From: Ronald Fenner <email@hidden>
  • Date: Mon, 13 Feb 2006 23:27:58 -0600

The problem boils down to namespaces. The exception class is inside
one it's missing from the sample. The test class in not inside one.
The compiler thinks the friend class is in the same namespace when
it's not. By wrapping the test class in a namespace, forward
declaring the class with the same namespace and then using the
namespace with the friend declaration the code compiles.

It'd be nice if the compiler could detect this type of problem and
give a better error message something like the not finding a function
and listing it's possible candidates in this case it'd list the
possible classes with namespaces.

Ron

On Feb 13, 2006, at 10:02 PM, Ronald Fenner wrote:

Ok I'm getting this compile error in Xcode with gcc 4.0
error: 'std::string CPG_ERROR_NS::CPG_Exceptions::m_What' is protected
cpg_exceptions-test.cpp:31: error: within this context

heres the relevant code:
class CPG_Exceptions
{
#ifdef UNIT_TESTING__
friend class CPG_Exceptions_Test;
#endif

public:
 static CPG_ErrorID m_ErrorID;

  explicit CPG_Exceptions();
  explicit CPG_Exceptions(CPG_SInt32 what_reason);
  explicit CPG_Exceptions(const CPG_String& what_reason);
  virtual ~CPG_Exceptions();

  CPG_SInt32 what();
  CPG_String swhat();
	CPG_Exceptions& ParseVariables(CPG_String inStr,...);

protected:
 CPG_String m_What; //<-- first line of error
 CPG_SInt32 m_NWhat;

virtual CPG_SInt32 GetErrorID() { return m_ErrorID.GetErrorID(); }
virtual CPG_String GetErrorString() { return m_ErrorID.GetErrorString(); }
};


void
CPG_Exceptions_Test::TestConstructors()
{
CPG_ERROR_NS::CPG_Exceptions exTest1;
CPG_ERROR_NS::CPG_Exceptions exTest2(5);
CPG_ERROR_NS::CPG_Exceptions exTest3(std::string("This is a test"));

CPPUNIT_ASSERT("" == exTest1.m_What);//<-- second line that goes with the error.
CPPUNIT_ASSERT_EQUAL(0, exTest1.m_NWhat);
CPPUNIT_ASSERT("" == exTest2.m_What);
CPPUNIT_ASSERT_EQUAL((CPG_SInt32)5, exTest2.m_NWhat);
CPPUNIT_ASSERT("This is a test" == exTest3.m_What);
CPPUNIT_ASSERT_EQUAL((CPG_SInt32)0, exTest3.m_NWhat);
CPPUNIT_ASSERT("Generic Exception Was Thrown" == exTest1.m_ErrorID.GetErrorString());
CPG_SInt32 errorID = CPG_ERROR_NS::CPG_ErrorIdTable::GetErrorID (CPG_String("CPG_Exceptions"));
CPPUNIT_ASSERT_EQUAL(errorID, exTest1.m_ErrorID.GetErrorID());
}


I've been googleing around for answer and have seen some problems with friend and read through a thread at idevgame on Inheritance and Visibilty but have yet to find a solution to the problem.
I would expect that since the class CPG_Exceptions_Test is made a friend it should have access to the protected variable a least in VS it does but then again VS is really leniant at times.


The only reason I'm using friend is so that the test cases have access to protected and private variables to make sure things get ititialized right and to bypass functions before they have been tested. The friend declarations are only compiled in when unit testing.

Blah if i can beat this error, 90% of the current build errors will disappear.

Thanks in advance.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Friend error with gcc 4.0 in Xcode (From: Ronald Fenner <email@hidden>)

  • Prev by Date: Friend error with gcc 4.0 in Xcode
  • Next by Date: PPC GCC problem with 3.3/OSX.3.9
  • Previous by thread: Friend error with gcc 4.0 in Xcode
  • Next by thread: PPC GCC problem with 3.3/OSX.3.9
  • Index(es):
    • Date
    • Thread