Code compiles for one computer, but not the other

This is a discussion on Code compiles for one computer, but not the other within the C++ Programming forums, part of the General Programming Boards category; Hello again. Elysia coded this code for me, but I can't ask her so I'll have to ask you peeps ...

  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 02: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
    Posts
    23,010
    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
    22,269
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    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, 08:35 AM
  2. Computer will not boot.
    By RealityFusion in forum Tech Board
    Replies: 25
    Last Post: 09-10-2004, 05: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, 06:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21