Thread: new IDirect3DTexture9 C++

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up new IDirect3DTexture9 C++

    I'm trying to make a texture wrapper for d3d 9.0c and I'm having trouble with my copy constructor.

    Code:
    TEXTURE::TEXTURE( const TEXTURE& temp )
    {
    	// ...
    
    	Texture = new IDirect3DTexture9;
    	*Texture = *temp.Texture;
    
    	// ...
    };
    I get the "error C2259: 'IDirect3DTexture9' : cannot instantiate abstract class" error and I know what the problem is (I think). But how am I supposed to get around this (I'm not 100% familiar with copy constructors so this could just be a general C++ question).

    Much appreciated!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, the member variable Texture is a pointer to IDirect3DTexture9. You do not know what is the exact type of the object that the pointer temp.Texture points to. Check the interface for IDirect3DTexture9. If it provides a clone() member function, use it:
    Code:
    Texture = temp.Texture->clone();
    If not, you might be reduced to using dynamic_cast to try all the possible derived classes of IDirect3DTexture9 until you find the correct one.

    Or maybe this TEXTURE class really should be non-copyable, in which case you should declare its copy constructor and copy assignment operator as private and do not implement them.
    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

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Anything called IBlahBlah is an abstract COM interface. You are not able to copy such objects. If the object is copyable, then there should be an exposed interface which allows you to copy it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You cannot call new on a COM object and expect it to work correctly.

    Use D3DXCreateTextureFromFile/Memory/Ex() or IDirect3DDevice9::CreateTexture() to create a pointer to a texture interface.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deleting objects, textures, and materials
    By infernosnow in forum Game Programming
    Replies: 11
    Last Post: 07-19-2006, 05:19 AM
  2. Vectors + Classes = Confusing
    By Epo in forum C++ Programming
    Replies: 59
    Last Post: 12-18-2004, 04:42 PM