Thread: Code compiles for one computer, but not the other

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    Code compiles for one computer, but not the other

    Hello again.

    Elysia coded this code for me, but I can't ask her so I'll have to ask you peeps :S
    Code:
    template<typename Type, typename LoadFncT, LoadFncT LoadFnc, void (CALL HGE::* FreeFnc)(Type)>
    
    class Resource {
    public:
    
    Type& get() { return m_Resource; }
    
    };
    Now I cut it abit so that you only have to see the necessary bit...
    When I try to call the get() function from a class that's inherited from Resource, it says
    Code:
    error C2039: 'get' : is not a member of 'Texture'
    But it works for Elysia, why? :S
    Thanks in advance
    Last edited by Akkernight; 03-10-2009 at 01:29 PM.
    Currently research OpenGL

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    the default access level for classes is private. private members aren't visible in derived classes. change it to this and it should work without making the method completely visible to the outside world
    Code:
    class Resource {
    protected: Type& get() { return m_Resource; }
    };

  3. #3
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Well, there is a public: there, I just forgot to add it :S sorry 'bout that!
    Currently research OpenGL

  4. #4
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Also, it doesn't have anything to do with SP1 ?
    I think I have it, but I'm not 100% sure...
    Currently research OpenGL

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Maybe you should show how you set up your Texture class.

  6. #6
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Resource.h
    Code:
    #ifndef resource_h__
    #define resource_h__
    
    #include "hge_wrapper.h"
    
    template<typename Type, typename LoadFncT, LoadFncT LoadFnc>
    struct LoadFncCallHelper {};
    
    template<typename Type, typename LoadFncT, LoadFncT LoadFnc, void (CALL HGE::* FreeFnc)(Type)>
    class Resource
    {
    public:
    	Resource(hge_wrapper& hge, const char* strResource): m_hge(hge)
    	{
    		m_Resource = LoadFncCallHelper<Type, LoadFncT, LoadFnc>::Call(hge, strResource);
    	}
    
    	~Resource()
    	{
    		(m_hge.get()->*FreeFnc)(m_Resource);
    	}
    
    	Type& get() { return m_Resource; }
    
    private:
    	void operator = (Resource&);
    	Resource(Resource&);
    	Type m_Resource;
    	hge_wrapper& m_hge;
    };
    
    #endif // resource_h__


    Texture.h
    Code:
    #ifndef texture_h__
    #define texture_h__
    
    #include "resource.h"
    
    typedef HEFFECT (CALL HGE::* TextureLoadFnc_ptr_t)(const char*, DWORD, bool);
    
    template<TextureLoadFnc_ptr_t LoadFnc>
    struct LoadFncCallHelper<HTEXTURE, TextureLoadFnc_ptr_t, LoadFnc>
    {
    	static HEFFECT Call(hge_wrapper& hge, const char* strResource)
    	{
    		return (hge.get()->*LoadFnc)(strResource, 0, false);
    	}
    };
    
    class Texture: public Resource<HTEXTURE, TextureLoadFnc_ptr_t, &HGE::Texture_Load, &HGE::Texture_Free>
    {
    public:
    	Texture(hge_wrapper& hge, const char* strEffect): Resource(hge, strEffect) {}
    };
    
    #endif // texture_h__
    The call
    Code:
    m_spr(m_tex->get(), tex_x, tex_y, tex_w, tex_h)
    There you go, I'll just give it all, hope Elysia won't mind xP
    Currently research OpenGL

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Problem seems resolved. Akkernight was using old code (including old headers).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Speaking of headers, I suggest changing resource_h__ to RESOURCE_H_, or something more likely to be unique, also fully capitalised, and yet not reserved to the implementation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Blame Visual Assist X -_-
    I'm tired of configuring it over and over again...
    Don't worry, though. I knew it was a poor name to begin with.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Computer will not boot.
    By RealityFusion in forum Tech Board
    Replies: 25
    Last Post: 09-10-2004, 04:05 PM
  3. how do you code in binary...
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 01-27-2003, 05:14 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM