Jump to content
  • Advertisement

Archived

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

Ataru

Template Woes

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have not been able to find any solution for this one. I want to acess some public members of a class using templates, and I get the weirdest compile error I've ever seen: "error C2248: 'MEM_BLOCK_LOCATION' : cannot access public member declared in class 'MEM_MANAGEABLE'" I've never heard of such a situation where I can't access a public member, here's the basic code, if someone can explain why, this would be great. I'm hacking up a workaround, but I'd rather do it this way, or at least understand why I can't. (I have removed some source to make the problem easier to understand
template <class T> struct MEM_BLOCK
{
	T* data;
};

class MEM_MANAGEABLE
{
public:
	int MEM_BLOCK_LOCATION;
};

template <class T> class _3D_FLY_MEM_ALLOCATOR  
{
public:
	_3D_FLY_MEM_ALLOCATOR()
	{
	}

	virtual ~_3D_FLY_MEM_ALLOCATOR()
	{
	}

	void __MA_NEW()
	{
		dataBlock[firstInactive].data->MEM_BLOCK_LOCATION = firstInactive; <-- fails here
		
	}
private:

	MEM_BLOCK<T>*	dataBlock;	
	int				firstInactive;
};

For some reason I cannot access this data, as I mentioned above, it says I can't access the private member. Why the **** not? I'm utterly confused. [edited by - ataru on February 26, 2004 9:23:50 PM]

Share this post


Link to post
Share on other sites
Advertisement
template <class T> struct MEM_BLOCK
{
T* data; //<------------------ NOT PUBLIC
};


dataBlock[firstInactive].data->MEM_BLOCK_LOCATION = firstInactive; // <-- fails here
// ^____ DUE TO HERE?


SiCrane is probably on the money, since you probably just deleted the ''public:'' in removing code to make the problem easier to understand, or some friends directive.

Share this post


Link to post
Share on other sites
I actually tried that, but MEM_BLOCK is a struct, the members are public by default.

I''m using Visual Studio 6.0

I am guessing it''s a compiler thing then

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You haven''t posted enough information about your problem. Can you post the code that''s using an object of class _3D_FLY_MEM_ALLOCATOR? My current guess is that the template parameter type isn''t of class MEM_MANAGEABLE and does not define the variable MEM_BLOCK_LOCATION.

Share this post


Link to post
Share on other sites
If the instantiation goes along the lines of:-

_3D_FLY_MEM_ALLOCATOR<MEM_MANAGEABLE> thingy;
thingy.__MA_NEW();

Then I can tell you that it works on VC.NET and VC6(sp5), oddly it compiles in gcc 3.1 but won't link, but that's probably my setup.

Jans.

On a side note - whatever you're doing, it doesn't look pretty.


[edited by - jansic on February 27, 2004 2:16:50 PM]

Share this post


Link to post
Share on other sites
I do instantiate it as as Jansic describes (actually from a class that inherits from MEM__MANAGEABLE.

I don''t think the code is too ugly, it allows me to re-use memory for multiple objects instead of new/deleting them all of the time. Getting a huge performance boost out of it.

Strange, i have SP5 installed, may be some weird VC bug. I am utterly confused as to why it won''t compile. I don''t even need to instantiate it, it won''t compile, the compiler does not like me accesing that data memeber for some odd reason. I am guessing now that it''s just bad template compiler support.

Share this post


Link to post
Share on other sites
quote:

I do instantiate it as as Jansic describes (actually from a class that inherits from MEM__MANAGEABLE.

If your derivation from MEM_MANAGEABLE uses private inheritance you probably won't be able to get at the base class members; ensure your derivation looks something like this:-
class DERIVED : public MEM_MANAGEABLE 

Jans.

[edited by - jansic on February 28, 2004 7:41:57 AM]

Share this post


Link to post
Share on other sites
Oh my god I suck so much. That was it. I was using multiple inheritance, the first inheritance was public, but MEM_MANAGEABLE was not.

Thanks a lot

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!