Operating System - HP-UX
1838407 Members
3079 Online
110125 Solutions
New Discussion

c++ compiler ( Old & New Version ) Friend Function problem

 
Rameshwar Miniyar
New Member

c++ compiler ( Old & New Version ) Friend Function problem

I am having Friend function problem in my Code. I have three files ( One C++ & two header files )

VIL >ls
CUc060XmlRequest.h CXmlConverter.C CXmlConverter.h

VIL:: >cat CUc060XmlRequest.h
#include
#include "CXmlConverter.h"

class CUc060XmlRequest
{
friend CXmlConverter::CXmlConverter();
friend CXmlConverter::CXmlConverter();
public:
protected:
private:
static void initXmlTagNames();
static void delXmlTagNames();
};
inline void CUc060XmlRequest::initXmlTagNames()
{
}
inline void CUc060XmlRequest::delXmlTagNames()
{
}



VIL: >cat CXmlConverter.C
#include
#include "CUc060XmlRequest.h"
#include "CXmlConverter.h"

CXmlConverter::CXmlConverter()
{
CUc060XmlRequest::initXmlTagNames();
}
CXmlConverter::~CXmlConverter()
{
CUc060XmlRequest::delXmlTagNames();
}


VIL: >cat CXmlConverter.h
#include
class CUc060XmlRequest;

class CXmlConverter
{
public:
CXmlConverter();
virtual ~CXmlConverter();
protected:
private:
};


VIL: >c++ *.C
"./CUc060XmlRequest.h", line 6.12: The attributes "friend" are not allowed.
"./CXmlConverter.h", line 4.7: CCN5403 (S) "class CXmlConverter" is already defined.
CCN0793(I) Compilation failed for file ./CXmlConverter.C. Object file not created.



Please help me to resolve the error "the attributes "friend" are not allowed. I am not able to resolve this. I am upgrading my compiler version from V2R10 to V1R2. It used to work for old compiler. Semantics for friend declaration have changed for new compiler.
1 REPLY 1
Peter Godron
Honored Contributor

Re: c++ compiler ( Old & New Version ) Friend Function problem

Hi,
Would you not require the term class between friend and the class name as CXmlConverter is a class, as you would need void or int or ... if it was a function ?

See have a look at:
http://www.codersource.net/cpp_tutorial_friend.html

The second (already defined) error would come from the inclusion of CXmlConverter.h both in CXmlConverter.C and CUc060XmlRequest.h.