|
If you need different function for int and double you need two different classes for they, and one template for others.
Why do you want your class todo different things width different types? This is not a application of templates. Templates are useful when types are diffrent and actions are same.
Hope will help you.
|
|
|
|
|
progDes wrote: Why do you want your class todo different things width different types?
The class is very big...many function are in common...but I need to differentiate the code in this 2 cases
...the problem is that I'm inside the class, I haven't found nothing into manuals/online helps. But I really need to solve this problem
Russell
|
|
|
|
|
Maybe reformulating the problem will help: what do you really need to do?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Probally ...got a way!
T Foo(){
T FakeParam;
return Foo(FakeParam);
}
private:
double Foo(double){
}
int Foo(int){
}
T Foo(T){
}
Needed some tests
Russell
|
|
|
|
|
In your case the only decision I see is macro class generation, not templates, macros. And of course #ifdef, #endif. But this is ugly, think about program design. This is bad approach.
|
|
|
|
|
I will maybe say something without sense... but... Why don't you make a way of trick to the compiler? I mean...
I make some additions to the SmartList of Simon Hughes here in codeproject. You can look for my article. The fact is...
If a CList can return whatever you give in the TYPE, ARG_TYPE.... Why don't you use that possibility? You can have some intermediate class that use your "typename T" as entry parameter and then you shouldn't have any problem more to return one type or another type of element. The return will depend on what you give to the ARG_TYPE.
I.E:
CMyList < TYPE, ARG_TYPE >& Foo (T tTemp)
{
return tTemp;
}
With that you return T independantly of what type of variable T is, being possible for complex classes too.
In my project I have some main ObjClass that have member variables and methodes that use secondary SubObjClass that have parameters and methodes that use third type of SubSubObjClass, so on till 5 steps in the hierarchy. And The main objects are saved in one of this list. The list can save different type of things and returns what it has saved in. No matter of what.
Im not meaning you should a CList with your elements, but maybe you can rewrite your template to return whatever you need using something like that.
I hope not saying silly things and that it helps you
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Nelek wrote: I will maybe say something without sense
No!! Why?
Interesting idea,
Thank You.
Russell
|
|
|
|
|
Hi,
My mainframe window has close,mini amd maxi buttons.
But it does not work.
I cannot close or minimize the window.
Whats the reason.
My Precreatewindow codes like
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style = WS_POPUP | WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
return CMDIFrameWnd::PreCreateWindow(cs);
}
Whats the reason?
Anu
|
|
|
|
|
I keep wonderring why you totally replace the cs.style value, convention is you should OR the desired extra styles with the passed in cs.style value. It is also unconventional to have a popup overlapped window, refer to MSDN CWnd::CreateEx Remarks section where it states "Creates an overlapped, pop-up, or child-window ...".
|
|
|
|
|
In addition to Roger's reply...
How do you know calling CMDIFrameWnd::PreCreateWindow() AFTER setting your values to cs won't completely overwrite yours?
You should call the base class first and THEN modify the appropriate values.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I modify my MainView style as follows:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{ if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.style = cs.style | WS_MAXIMIZE;
return TRUE;
}
and it works fine.
Hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi,
I have MFC code written on VC6 platform.Now im trying to build the same code in VS2005 platform.Im getting following linking error.
Error 1 error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in MyCtrl.obj MY_FileIO.lib
Where MyCtrl.cpp is in the application project and MY_FileIO is a project for DLL used by application.
Whats the cause and whats the solution for the same?
|
|
|
|
|
Probably you are trying to use both iostram library and std library.
Your dll and application should use same type of libraries.
If your dll uses MFC then modify the project setting accordingly.
I have not used VS 2005, but here is the way to set application use MFC in VS 6.0
Project > Settings > General tab. "Select Use MFC in Shared Dll"
|
|
|
|
|
Verify that both your dll and axecutable use the same run-time library. For that, open the project properties -> "C/C++" and verify that "Runtime Library" is the same for both projects.
|
|
|
|
|
My Application and DLL has "Multi-threaded Debug (/MTd)" setting set in RunTime library.Still it has the linking error.
|
|
|
|
|
is
#include "stdafx.h"
writed on the top of that file ?
Russell
|
|
|
|
|
and / or
#pragma once
?
Russell
|
|
|
|
|
Even it had #pragma once statement in the corresponding .h file.
|
|
|
|
|
Yes.
#include "stdafx.h" statement is included in the .cpp file.
I tried setting "configuration Property->General->use of MFC" to "Use MFC in shared DLL ".It gave me many more linking errors (like RegSetValueEx is not defined.)
i red this link http://support.microsoft.com/kb/148652.Even this didnt helped me much.
|
|
|
|
|
Hello everyone,
I am using Windows API open (create) a new file by CreateFile,
http://msdn2.microsoft.com/en-us/library/aa363858.aspx
the return value is HANDLE, if I use fwrite to write content to the file, since fwrite requires FILE* as parameter. I think HANDLE is not the same as FILE*, right?
Are there any ways (or methods) to transform HANDLE to FILE*?
I have tried that passing HANDLE directly to fwrite (forcely convert from HANDLE from FILE*) will cause access violation exception. I think the reason is HANDLE is not the same as FILE*, is that correct?
thanks in advance,
George
|
|
|
|
|
You should be using WriteFile() with CreateFile().
|
|
|
|
|
As already suggested by Jonathan Wilkes: "you should be using WriteFile() with CreateFile()".
Alternatively you can use fopen to open the file and then fwrite to write into the file itsef. Bottom line: be consistent.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
It seems easier to convert from FILE * to HANDLE :
#include <io.h>
#include <fcntl.h>
FILE * f = . . .;
HANDLE h = (HANDLE)_get_osfhandle(fileno(f));
The other conversion looks longer:
HANDLE h = . . .
FILE * f = _fdopen(_open_osfhandle((intptr_t)h, _O_RDONLY), "rb");
I hope this works. I am not sure mixing of operations with FILE * and HANDLE cannot be avoided.
|
|
|
|
|
Viorel. wrote: I hope this works. I am not sure mixing of operations with FILE * and HANDLE cannot be avoided
In fact the mix can usually be avoided (and should be avoided, at least to maintain the code coherence). There are, of course, exceptions...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi Friends ...
I have to install the dll build in VS2005 ? It is giving error to install that dll? I installed Framework2.0 on the same machine still there is problem exists.
I have also copied mfc71.dll in sytem32 folder?
What should I do to register my dll?
Please help me ...
Thanking You...
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|