Another Syntax Error? Setting a pointer equal to another..

This is a discussion on Another Syntax Error? Setting a pointer equal to another.. within the C++ Programming forums, part of the General Programming Boards category; Okay, it won't let me set RenderObject->pModel = Models.Return_Resource_Reference (Filename); Here is the header file, I'll bold the right lines.. ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Another Syntax Error? Setting a pointer equal to another..

    Okay, it won't let me set RenderObject->pModel = Models.Return_Resource_Reference (Filename);


    Here is the header file, I'll bold the right lines..

    Resource_Manager.h
    Code:
    #pragma warning(disable: 4786)
    
    #include <vector>
    #include "MS3D.H"
    #include <map>
    
    class Resource_Cache
    {
    friend class Resource_Manager;
    public:
    	struct	MS3DModelRenderData
    	{
    		float Position[3]; // will be changed to vectors eventually
    		float Orientation[3];
    		MS3DModel *pModel;
    	};
    
    	std::vector<MS3DModelRenderData*> MS3DModels; // holds pointers to all MS3D Models
    private:
    
    	bool Add_MS3DModel_To_Cache(std::string Filename); // loads a milkshape model to the cache
    
    };
    
    template < typename resource_t >
    class Manager
    {
    
        std::map< std::string , resource_t* > Resources;
    
    public:
    
    	bool Check_Existance( const std::string & filename );
        resource_t & Return_Resource_Reference( const std::string & filename );
    	
    
    	virtual ~Manager( void )
    	{
    		std::map< std::string ,  resource_t * >::iterator destroyer, end;
    		for ( destroyer = Resources.begin() , end = Resources.end() ; destroyer != end ; ++destroyer ) 
    		{
    			delete destroyer->second;
    		}
    	}	
    
    };
    
    class Resource_Manager
    {
        Manager<MS3DModel> Models;
    
    	std::string get_extension(std::string Filename);
    
    public:
    	void Add_Resource(std::string Filename)
    	{
    		
    		if (get_extension (Filename ) == "ms3d")
    		{
    			if ( Models.Check_Existance (Filename) == true  )
    			{
    				Resource_Cache::MS3DModelRenderData  *RenderObject = new Resource_Cache::MS3DModelRenderData;
    				RenderObject->pModel = Models.Return_Resource_Reference ( Filename );
    				// GlobalResources.MS3DModels.push_back()
    			}
    		}
    		
    	}
    
    };
    And Resource_Manager.cpp

    Code:
    #include "Resource_Manager.h"
    #include <windows.h>
    
    ////////////////////////////////////
    // Resource Cache //////////////////
    ////////////////////////////////////
    bool Resource_Cache::Add_MS3DModel_To_Cache(std::string Filename)
    {
    	MS3DModelRenderData *Model;
    	Model = new MS3DModelRenderData;
    	Model->pModel = new MS3DModel;
    
    	if ( Model->pModel->Load_MS3D_Model( Filename ) == false )
    	{
    		MessageBox( NULL, "Couldn't load the model data.", "Error", MB_OK | MB_ICONERROR );
    		return 0;									// If Model Didn't Load, Quit
    	}
    
    	 MS3DModels.push_back(Model); 
    
    	return 1;
    }
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    
    ///////////////////////////////////////////////
    // Manager Template ///////////////////////////
    ///////////////////////////////////////////////
    template < typename resource_t >
    resource_t & Manager<resource_t>::Return_Resource_Reference(const std::string & filename ) 
    {
    	std::map< std::string , resource_t* >::iterator entry = Resources.find( filename );
        if ( entry != resources.end() ) // if the entry is found
    	{ 
    		return * entry->second; // return the reference to the resource
        } 
    /*
    	else
    	{
    
    		resource_t* resource( new resource_t( filename ) );
    		
    		// first we gotta load the resource, then we can make a pair
    		// and return the reference
    	
    		resources.insert( std::make_pair( filename , resource ) );
    		return * resource;
        }
    */
    }
    template < typename resource_t >
    bool Manager<resource_t>::Check_Existance( const std::string & filename )
    {
    	std::map< std::string , resource_t* >::iterator entry = Resources.find( filename );
        if ( entry != Resources.end() ) // if the entry is found
    	{ 
    		return true;
        } 
    	else return false;
    }
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    
    
    
    ///////////////////////////////////////////////
    // Resource Manager ///////////////////////////
    ///////////////////////////////////////////////
    std::string Resource_Manager::get_extension(std::string Filename)
    {
    	std::string::size_type last_dot_index = Filename.rfind( '.' );
    	std::string extension = Filename.substr( last_dot_index + 1 ); //+1 to not include the dot...
    	return extension;
    }
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    And here is the error I get..

    Code:
    \\student\courses\cedar_cliff\computer\senior project\auditorium\resource_manager\resource_manager.h(63) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class MS3DModel' (or there is no acceptable conversion
    For some reason it thinks I'm not setting an MS3DModel pointer equal to another MS3DModel pointer...

    Strange.. Help plzzz?
    [/code]
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > RenderObject->pModel = Models.Return_Resource_Reference ( Filename );
    Not sure, but I'm guessing you want to make this:
    Code:
    				RenderObject->pModel = &Models.Return_Resource_Reference ( Filename );

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Yes, remember that pointers and references are different.
    Code:
    std::map< std::string , resource_t* >::iterator entry = Resources.find( filename );
        if ( entry != resources.end() ) // if the entry is found
    	{ 
    		return * entry->second; // return the reference to the resource
        }
    Do you think it's a good idea to return a reference to a local variable? It isn't.
    Code:
    Get immediate answers to your questions, join us on IRC!                If you can't read this,
    Server: 72.20.18.117                                                    you use a crappy screen 
    Channel: #tech                                                          resolution.
    Do you know Sly?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Yeah, anyways..

    People at gamedev are telling me this is a bad way to deal with this...

    Something about "hanging pointers"???

    I'll update my peer review post with the latest code...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 06:29 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 12:54 PM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

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