|
Try
template<typename T>
class A
{
// Blah
};
template<typename T>
class B : public A<T>
{
// Blah
};
Template classes can inherit from non-template classes (using standard syntax).
Dave
|
|
|
|
|
Actually, when you derive from a template class you don't use the template keyword if the derived class has no template params of its own. In ATL you do this:
class CSomeWnd : public CWindowImpl<CSomeWnd>
{ ... }; all the time
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Actually, The derived and the base has the same template params.
template <class type="">
class CBaseClass
{
}
what would the derived class look like?
I want to use a template class as a param in the other template class.
I am really not sure how the syntax goes with this.
class CClass: public CBaseClass<x>
{
}
will give errors as to what X is.
I get a LINK2001 when I put
template <class type="">
class CClass:public CBaseClass<type>
{
}
So how do I declare this?
|
|
|
|
|
(Note for the future: you need to escape < and > (use the buttons below the sig box if you're in IE/Mozilla) for template syntax to appear correctly.)
There are two ways to approach deriving from a template class. 1, you can make the derived class a template; or 2, you can derive from a specialization of the base class. Take this class:
template <typename T>
class A
{
public:
A ( T t ) : m_t(t) { }
T m_t;
};
A<char> a_obj('x'); Pretty simple class with one data member, whose type is passed as the template param. If I want to make a derived class, I can write this:
class B : public A<int>
{
public:
B(int n) : A<int>(n) { }
};
B b_obj(1); Note that objects of type class B will only use the A<int> specialization. You can't have a class B object use, say A<unsigned long> .
The other way is to have the derived class be a template:
template <typename T>
class C : public A<T>
{
public:
C(T t) : A<T>(t) { }
};
C<double> c_obj(3.14); Of course, you can always make the derived class more complicated if you need to:
template <typename T, typename U>
class D : public A<T>
{
public:
D(T t) : A<T>(t), m_u(0) { }
U m_u;
};
D<float,int> d_obj(2.71828); Yes, the syntax sucks. You just have to keep staring at it and seeing examples until it sinks in.
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I am still not g etting this. I am tons of errors. What is the syntax if you declare the class functions outside the template class itself? Where can I look up more examples or a tutorial on this? I have been looking but seem not to be able to find anything on this subject, only on direct use and declarations of templates not deriving from templates.
THanks.
|
|
|
|
|
Errors with what? With your own code? In that case you need to post the code and the errors you're getting.
It'd probably be best to start a new thread, since this one is well-buried by now.
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Agreed. But the original question asked how to derive a template class from another template class, not a non-template class from a template class as you have done here.
Dave
|
|
|
|
|
Hello,evryone! this is the first time i come to a foreign forum,
I am a chinese, and english is poor, you can realize it from my words. ^_^
i want to learn english and programming here,so it's only a try. please help me over time!
Hello!
|
|
|
|
|
Hi, I wonder what's fastest to check if a child control (hWnd) is visible?
IsWindowVisible(hWnd) -or-
GetWindowLong(hWnd, GWL_STYLE) & WS_VISIBLE
First line checks specified window, its parent window (its parent's parent window and so forth) have the WS_VISIBLE style. Second line checks only the specified window. When I check I already know that parent etc is visible, so is second line the fastest solution?
Thx, Moak
|
|
|
|
|
hm, I'll take GetWindowLong()
|
|
|
|
|
Ok.. I dug out one of my old VC++ books Inside Visual C++ Version 4. I read the section on dlls after post many questions here and I still can't seem to get a pointer to my function. Following is the code I am using if anyone has any ideas it would be appreciated.
Thanks,
-Eric
Created this dll using the dllWizard as a shared MFC regular dll.<br />
This is the only exported function in the dll.<br />
__declspec(dllexport) CString SndMessage(CString strInMessage)<br />
{<br />
CString strOutMessage = _T("Inside TestDll.dll->SndMessage() ");<br />
<br />
strOutMessage += strInMessage;<br />
<br />
return strOutMessage;<br />
}<br />
<br />
This is in the Dialog header file as public.<br />
typedef CString (SNDMESSAGE)(CString);<br />
HINSTANCE hDllHandle;<br />
SNDMESSAGE *fpFunction;<br />
<br />
Inside my OnInitdialog().<br />
hDllHandle = ::LoadLibrary(_T("TestDll.dll"));<br />
if(hDllHandle == NULL)<br />
MessageBox(_T("Error loading TestDll.dll"));<br />
else<br />
{<br />
fpFunction = (SNDMESSAGE *)::GetProcAddress((HMODULE)hDllHandle, "SndMessage");<br />
<br />
if(fpFunction == NULL)<br />
{<br />
MessageBox(_T("Error obtaining address of SndMessage() in TestDll.dll"));<br />
PostMessage(WM_QUIT);<br />
}<br />
}<br />
<br />
void CTestingDllDlg::OnButtonTest() <br />
{<br />
UpdateData(TRUE);<br />
<br />
m_strOutText = (*fpFunction)(m_strInText);<br />
<br />
UpdateData(FALSE);<br />
}<br />
<br />
|
|
|
|
|
The problem is you are exporting a C++ function and its name to the outside world is not SndMessage. C++ mangles the name of functions so that the arguments types are included. If you have successfully built your DLL you can find out exactly what the exported name is by typing "dumpbin /EXPORTS TestDll.dll" Dumpbin is one of the VC++ tools.
One work around is to export a straight C function that exports a pointer to the string that is passed via a LONG and you cast it to a string pointer when you use it. This can be wrapped in a local C++ function so don't see the messy details.
Note - in your current implementation, I believe that strOutMesage will be destroyed when SndMessage returns since it is then out of scope.
The Ten Commandments For C Programmers
|
|
|
|
|
Rick York wrote:
The problem is you are exporting a C++ function and its name to the outside world is not SndMessage. C++ mangles the name of functions so that the arguments types are included. If you have successfully built your DLL you can find out exactly what the exported name is by typing "dumpbin /EXPORTS TestDll.dll" Dumpbin is one of the VC++ tools.
One work around is to export a straight C function that exports a pointer to the string that is passed via a LONG and you cast it to a string pointer when you use it. This can be wrapped in a local C++ function so don't see the messy details.
When I run Dumpbin this is what I get:
Dump of file TestDll.dll
File Type: DLL
Section contains the following exports for TestDll.dll
0 characteristics
3E1E3F7D time date stamp Thu Jan 09 22:35:25 2003
0.00 version
1 ordinal base
0 number of functions
0 number of names
ordinal hint RVA name
Summary
F000 .data
5000 .idata
11000 .rdata
C000 .reloc
4000 .rsrc
10F000 .text
Rick, any chance you can explain the second part of that to me?
Thanks,
-Eric
|
|
|
|
|
It sounds to me like you need to use a .def file. I'm not positive, but if it's the GetProcAddress that's failing, this is probably the case.
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
Change:
__declspec(dllexport) CString SndMessage(CString strInMessage)
to:
extern "C" __declspec(dllexport) CString SndMessage(CString strInMessage)
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I think this would help but I think the CString created will be gone once it is out of scope. I think the CString needs to be new-ed and passed as a pointer.
The Ten Commandments For C Programmers
|
|
|
|
|
What is OLE object? How to create it in VC++?
|
|
|
|
|
|
Can someone please help!!
When I try and displays numbers in hex using the setf(ios::hex) member function of the cout stream class with the string class header defined the numbers do not display in HEX.
the following code works and the number display correctly in hex
#include <iostream.h>
//#include <string>
//using namespace std;
int main()
{
int x = 0xff;
cout<<x<<endl;
cout.setf(ios::hex);
cout<<x<<endl;
return 0;
}
but when i try this the number does not display in hex
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x = 0xff;
cout<<x<<endl;
cout.setf(ios::hex);
cout<<x<<endl;
return 0;
}
Can someone please explain???
thanks
-perseus
|
|
|
|
|
Use an I/O manipulator for that:
cout << hex << x << endl;
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
thanks for your help. i knew it had to be something simple
-perseus
|
|
|
|
|
Hi All,
anybody know of some spots on the web to find icons I can use in my programs?
Thank You
|
|
|
|
|
http://www.iconarchive.com
http://www.iconnews.freeserve.co.uk/page2.html
http://www.iconfactory.com
http://groups.yahoo.com/group/glyphs/messages
Should be enough to get ya started
And the clickety police can sod off!
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
|
Hi guys!
I'm a beginner and I have some problems with the project I am working. It's a MDI without doc/view.
I just want to know how I can use a splash screen. I have read that there was a splash screen component in VC++ 6 but I cannot find it in .NET. Also, I want to change the icon and the title of my child windows. I've been able to change the size and the position of my child windows but I can't change the name and the icon.
I used
BOOL OpenGL_ContextMFC::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying theCREATESTRUCT cs
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
cs.lpszName="My new name here doesn't work";
cs.cx = 500;
cs.cy = 500;
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.lpszClass = AfxRegisterWndClass(0);
return TRUE;
}
any ideas?
thanks
|
|
|
|