Archived

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

use of class template requires template argument list ---> ???

This topic is 5619 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

When i'm trying to compile my program, I get the following error: d:\cpp\class\bmp.h(13) : error C2955: 'CBasicDraw' : use of class template requires template argument list I've a class CBmp derived from a class CBasicDraw, which use's templates. CBasicDraw is declared like this:
  
template <typename var >
class CBasicDraw{
protected:
	DDSURFACEDESC2 m_ddsd;
	long m_lPitch;
	var *m_lpsDest;
public:
	CBasicDraw(){
		INIT_DX_STRUCT(m_ddsd);
		m_lPitch=0;
		m_lpsDest=NULL;
	}
// a lot more code

} 
  
and CBmp like this:
  
class CBmp : public CBasicDraw{
private:
	BITMAPFILEHEADER m_FileHeader;
	BITMAPINFOHEADER m_InfoHeader;
	RGBQUAD *m_lpPalette;
	BOOL m_bSrcColorKey; 
public:
	LPDIRECTDRAWSURFACE4 m_lpsImage;
	DWORD m_dwWidthPixels, m_dwHeightPixels;
	CBmp();
	~CBmp();
	BOOL Load(char *lpcFileName, BMPLOADDESC LoadDesc);
	BOOL SetPalette(LPDIRECTDRAWPALETTE lpddPalette, int iNrStart=0, int iNrEnd=256);
	BOOL Draw(LPDIRECTDRAWSURFACE4 lpsDest, int xDest, int yDest, RECT *lprSrc=NULL);
};
  
I have totally no idea of what's wrong so I hope that anybody here does.. Merwin [edited by - Merwin van Dijk on July 26, 2002 8:25:26 AM] [edited by - Merwin van Dijk on July 26, 2002 8:27:49 AM] [edited by - Merwin van Dijk on July 26, 2002 8:36:00 AM]

Share this post


Link to post
Share on other sites
When deriving CBmp from CBasicDraw you''ll need to specify the templated type of var.
In effect, your CBmp class will need to be declared for instance like this:

  
class CBmp : public CBasicDraw<int> {
/* Stuff */
};


(Not actually having access to a compiler on this computer I''m not 100% certain this is the correct answer, but I''m fairly certain as I recently ran into the same problem while coding a generic set of classes for symmetric/assymetric encryption/decryption).

-Neophyte

Share this post


Link to post
Share on other sites
Thanks for the trouble. But with this answer a new question arises. I've designed CBasicDraw in a way it can draw 8, 16, 24-bit pixels. CBmp can load and draw a bitmap of 8, 16 and 24 bits with the help of CBasicDraw. But this wil not work if I have to specify the templated type of var. Also CBmp does not need to be templated because the function itself can determine howmuch bpp the image uses. Can someone help me with this problem?


[edited by - Merwin van Dijk on July 26, 2002 1:28:40 PM]

Share this post


Link to post
Share on other sites
You''ve got yourself in trouble there

Templates are compile-time only. You have to decide at compile-time what bit depth your draw code handles, if you want to do it any other way, you can''t use templates to do it.

Share this post


Link to post
Share on other sites
Making CBmp a template class as well should work fine.
For instance:

  
template <typename var>
class CBasicDraw {
/*
...
*/
};

template <typename var>
class CBmp : public CBasicDraw<var> {
/*
...
*/

};


-Neophyte

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com

Share this post


Link to post
Share on other sites