#### Archived

This topic is now archived and is closed to further replies.

# New friend problem

This topic is 5607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve gotten around it, but I get the impression since I have the problem in one file but not the other that I have some bad code somewhere.... here is some code snippets from the two different files. #ifndef H_POBJECTREF class PENGINE_API PObjectRef; #endif /* H_POBJECTREF */ //the object class class PENGINE_API PObject { friend PObjectRef; #ifndef H_PLIST class PENGINE_API PList; #endif /* H_PLIST */ //the list node class class PENGINE_API PNode { friend PList; First off, those H_P------ defines I put at the begining of each header as an inclusion guard. Next When I compile it the PObject class has NO problems (thanks to those guys that helped me with learning the friends stuff)... But the PNode class gives me these errors unless I write that friend line: friend class PList; error C2433: ''PList'' : ''friend'' not permitted on data declarations error C2501: ''PList'' : missing storage-class or type specifiers error C2244: ''PList'' : unable to resolve function overload I know I got around the compiler errors, but I''m still worried I have some bad code there with my lack of friend keyword experience. O and I checked to see if PList was used before, I couldn''t find it anywhere in any of my include folders. Pat - Ex nihilo nihilus

##### Share on other sites
Err... what the heck? Why aren''t you ever defining the inclusion guard? why aren''t you closing your classes? why are you putting the endif in the middle of the file?

Post enough code that we can actually tell what''s going on. Also, it''s a good idea to put it in [ source ] and [ /source ] tags (remove the spaces), and also to label your files.

How appropriate. You fight like a cow.

##### Share on other sites
There is code above each of those, and below each. The inclusion guards aren''t actually shown there, and I only put them on either side of that class def. to be POSSITIVE the class isn''t defined already (its just being over careful).

Yes I do close my classes.

The reason I don''t put all my code on is because many people complain (including myself) about filtering through alot of code. I figured you guys wouldn''t want about 6 pages of code, when really thats all that I can see as relavent.

It''s obvious that its something todo with the word PList because thats the only thing that is different between the two (other than the name of the class that its in, but that shouldn''t matter).

But here is a gutteted version of the code (fixes the problems you talked about, just as they are in my files)

//PObject.h
#ifndef H_POBJECT#define H_POBJECT...#ifndef H_POBJECTREFclass PENGINE_API PObjectRef;#endif /* H_POBJECTREF *///the object classclass PENGINE_API PObject{friend PObjectRef;...};#endif /* H_POBJECT */

//PNode.h
#ifndef H_PNODE#define H_PNODE...#ifndef H_PLISTclass PENGINE_API PList;#endif /* H_PLIST *///required includes#include "PObject.h"//the list node classclass PENGINE_API PNode{friend PList;...};#endif /* H_PNODE */

and yes those ellipsis (...s) are were there is more code, such at members, and method deffinitions. Import/Export macros, ect.

Pat - Ex nihilo nihilus

##### Share on other sites
What''s all this ''PENGINE_API'' stuff?

"class PENGINE_API PList;" might look to the compiler like: "give me an instance of PENGINE_API and call it PList."

"friend PList;" will then look like "set that object called PList as a friend", which gives you "''friend'' not permitted on data declarations".

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633710
• Total Posts
3013486
×