|
You need to add the extra typename when you refer to a nested type of a class that is dependant on a template parameter in a template. It tells the compiler it's a type and in this case to interpret the "*" as a pointer not multiplication.
e.g.
template<typename TYPE, typename ARG_TYPE>
typename CBanana<TYPE, ARG_TYPE>::CApple*
\-----------\/------------/ \-\/-/
2. Is nested in this class 1. This nested type
which is dependant on the
template parameters 'TYPE'
and 'ARG_TYPE'.
CBanana<TYPE, ARG_TYPE>::GetApple(typename CBananaa<TYPE, ARG_TYPE>::CApple* pApple)
{
return pApple;
}
The same goes for the other use of typename. The reason you need to do this is quite involved but actually quite reasonable once you understand it.
Steve
|
|
|
|
|
typename and class are interchangible when dealing with templates. That is, in that case, they mean the exact same thing.
Hmm, hit pre and it posted it. Anyway, the following should work (don't have Visual Studio on this box, so I can't test it to be sure):
template<class TYPE, class ARG_TYPE>
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class TYPE, class ARG_TYPE>
int CBanana<TYPE, ARG_TYPE>::GetInt(int i)
{
return i;
}
template<class TYPE, class ARG_TYPE>
CBanana<TYPE, ARG_TYPE>::CApple*
CBanana<TYPE, ARG_TYPE>::GetApple(CBanana<TYPE, ARG_TYPE>::CApple* pApple)
{
return pApple;
}
You shouldn't need the typename specifier in the method signature (though, it won't necessarily hurt it, it can make the code a bit less readable).
-- modified at 12:12 Tuesday 25th July, 2006
|
|
|
|
|
Zac Howland wrote: You shouldn't need the typename specifier in the method signature
This is not the case. As I explained in a previous post you need to add a typename in a template if you refer to a type which is nested in another type which is dependant on a template parameter. In this context you can NOT use class . See here[^] for Microsoft's explaination.
|
|
|
|
|
I stand corrected. After looking at a few of the documents, I think I never ran into this issue because I almost always typedef in those situations.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
No that didn't work either, but I'm sure a bright bunch like yourselves
can fill in the missing angle brackets and formatting.
Sorry,
Nvat.
|
|
|
|
|
instead of reposting again and again... edit (use the [Modify] link at the bottom of your thread) and check the "Ignore HTML tags in this message (good for code snippets)" checkbox below the emoticons...
|
|
|
|
|
My previous copy / paste from Visual Studio didn't
work properly. Should have been :
template<class type,="" class="" arg_type="">
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class type,="" class="" arg_type="">
int CBanana<type, arg_type="">::GetInt(int i)
{
return i;
}
template<class type,="" class="" arg_type="">
CBanana<type, arg_type="">::CApple*
CBanana<type, arg_type="">::GetApple(CBanana::CApple* pApple)
{
return pApple;
}
Nvat
|
|
|
|
|
use check box 'ignore HTML Tags..." (present below) while posting code. modify your post by checking the option. That will make full code available for reading
|
|
|
|
|
Hi,
when I try to compile the following code
template<class type,="" class="" arg_type="">
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class type,="" class="" arg_type="">
int CBanana<type, arg_type="">::GetInt(int i)
{
return i;
}
template<class type,="" class="" arg_type="">
CBanana<type, arg_type="">::CApple*
CBanana<type, arg_type="">::GetApple(CBanana::CApple* pApple)
{
return pApple;
}
which is based on code found in the MFC afxtempl header, I get a compile
error on the line CBanana<type, arg_type="">::CApple*
syntax error : missing ';' before '*'
if I replace the above return type with an int it then complains
instead about the parameter CBanana::CApple* pApple
'pApple' : undeclared identifier
it doesn't like my CApple !
Any ideas why ?
Nvat.
|
|
|
|
|
What is ATL, WTL, STL? When these are needed? where can i use them
Mathumala
|
|
|
|
|
|
toxcct wrote: see, it's not that complicated to use the web to search for something... i'm pretty sure you could do tit by yourself
But, Google is so complicated to use ..... :-P
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi All,
Im writing a dll in ATL COM called by a vb.net client. the client passes a 2d integer array when it calls MyMethod.
i have tow problems
I. i have trouble accessing the values in the array passed, i get junk values. this is the code.
<br />
STDMETHODIMP ExposedATLClass::MyMethod(SAFEARRAY **psa)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
long arrlengthx,arrlengthy;<br />
long **myarray;<br />
int indexx,indexy;<br />
try<br />
{<br />
arrlengthx=(*psa)->rgsabound[0].cElements;<br />
arrlengthy=(*psa)->rgsabound[1].cElements;<br />
myarray=(long**)malloc(arrlengthx*sizeof(long**)); <br />
for(long tempvar=0;tempvar<=arrlengthx;tempvar++)<br />
{<br />
myarray[tempvar]=(long*)malloc(arrlengthy*sizeof(long*));<br />
}<br />
SafeArrayAccessData(*psa,(void**)myarray);
char details[100];<br />
for(int tempx=0; tempx<=arrlengthx; tempx++, indexx++, indexy=0)<br />
{<br />
for(double tempy=0; tempy<=arrlengthy; tempy++, indexy++)<br />
{<br />
sprintf(details,"%d %d %d",indexx,indexy,myarray[indexx][indexy]);<br />
this->Error_Logger(details);
}<br />
}<br />
}<br />
catch(CException ex)<br />
{<br />
char error[300];<br />
ex.GetErrorMessage(error,300);<br />
this->Error_Logger(error);<br />
ex.Delete();<br />
}<br />
return S_OK;<br />
}<br />
in the program
SafeArrayAccessData(*psa,(void**)myarray); returns success
other methods i've used to access data are (replace the line "SafeArrayAccessData(*psa,(void**)myarray);" with code below )
1. using SafeArrayGetElement
<br />
long ai[2]={0,0}<br />
for(int temx=0;temx<=arrlengthx;temx++,ai[0]++)<br />
{<br />
for(int temy=0;temy<=arrlengthy;temy++,ai[1]++)<br />
{<br />
SafeArrayGetElement(*psa,ai,&myarray[temx][temy]);<br />
}<br />
}<br />
here SafeArrayGetElement(*psa,ai,&myarray[temx][temy]); returns index out of bounds
2. using safearraylock/unlock
<br />
<br />
both lock and unlock returned success
all methods return this junk value for myarray[indexx][indexy] -842150451
the values of indexx and indexy are correct and so are the boundaries.
II. my other problem.. no exception is logged.
where am i wrong. pls help
Thanks in advance
Nikhil
|
|
|
|
|
I have add teh active-x control in my project:
Open the Project in which intend to use an ActiveX control.
Project | Add To Project | Components and Controls. Taken to the Gallery where choose from Registered ActiveX Controls. Click the Control from the list and click Insert. choose the Control from a list and to confirm the names of the wrapper files which will be created.
From there i got a active=x in dialog box and the wrapper class also.
Now i need to know I have to login to server to take data from that and store in my system.
1: should i need to include ATL controls in my project?
2. how to make use of wrapper class and active-x controls?so thst i can login to server
3. Function in my .cpp file are as follow(API function).
CString CArielAPI::GetServerAddress(LPCTSTR SessionId)
{
CString result;
static BYTE parms[] =VTS_BSTR;
InvokeHelper(0x15, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, SessionId);
return result;
}
String CArielAPI::Login(LPCTSTR UserName, LPCTSTR Password, LPCTSTR UserId)
{
//username = wwtest2;
//Password = RD9234;
//Userid = wwtest2;
CString result;
static BYTE parms[] =VTS_BSTR VTS_BSTR VTS_BSTR;
InvokeHelper(0x2, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,UserName, Password, UserId);
return result;
}
4: IfATL is needed then how to work with that any help.....?????
|
|
|
|
|
1. No, you're using MFC wrappers.
2. You need to make sure that you create an instance of an 'CArielAPI' object.
Once you've done that, you should be able to call the various methods as you need to. Is there a 'Create' function (or similar name) generated in that class?
3. Refer to the documentation for the control
4. See #1
Steve S
Developer for hire
|
|
|
|
|
i have this function.But i am in great confusion whre should i create object ex:arielapi wartzodlcom.dbaccess.
CString CArielAPI::CreateOrder(LPCTSTR SessionId, long MarketNo, LPCTSTR Amount, short BuySell, short StopLimit, LPCTSTR RequestedPrice, short TradeType, LPCTSTR Exchange, short GoodTil, LPCTSTR GoodTilTime, LPCTSTR Instructions, LPCTSTR Account, LPCTSTR ClientRef)
{
CString result;
static BYTE parms[] =
VTS_BSTR VTS_I4 VTS_BSTR VTS_I2 VTS_I2 VTS_BSTR VTS_I2 VTS_BSTR VTS_I2 VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR;
InvokeHelper(0x7, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,
SessionId, MarketNo, Amount, BuySell, StopLimit, RequestedPrice, TradeType, Exchange, GoodTil, GoodTilTime, Instructions, Account, ClientRef);
return result;
}
|
|
|
|
|
Ah, no. That won't create an object, that calls a method on the object.
I'd do some background reading on using ActiveX controls in MFC if I were you. If you have VC6, the 'How do I..' in the help isn't too bad.
Steve S
Developer for hire
|
|
|
|
|
(Posted it in C# session but received none answer so I thought here it would be more appropriate)
Hi!
All I want is to create a BHO (Browser Helper Object) which among the other things it does, it displays something onto the IE's statusbar. The problem is how to access the rest fields of the IE's statusbar.
IWebBrowser2 gives only access to StatusText which is the first field from the 7 (as I can see in my IE).
I want to add a small icon to a statusbar field and when clicked do some stuff.
thanks,
eLefas
|
|
|
|
|
When I am trying to use sendmessage to load property page to FireFox browser using the message below ( ,which is successful in IE. )
gives error. Any Alernative for mozilla FireFox.
::SendMessage(m_hWnd, PSM_INSERTPAGE, 0, (LPARAM)&m_EditPage.m_psp);
|| ART OF LIVING ||
|
|
|
|
|
Is there any way to simulate the press of 'ENTER' key on IE.We have a password field,which invokes a javascript function to log the user in,on press of ENTER.
We need to reproduce this action automatically - ie after filling the userid and password,we need to invoke the ENTER key.
We fill up the userid/password fields by elem->setAttribute(..,..,0),where pelem is the IHTMLElement interface.
But we are not able to simulate the press of ENTER.
Any help will be appreciated.
thanks.
|
|
|
|
|
Hi All,
My requirements needs me to pass an instance of a class xyz in a third party component(OCX) to my dll in ATL COM. how do i go about this?
We all know that passing parameters in the constructors of the exposed atl classes/objects is literally impossible unless i write my own atl library(oops sorry bad joke!).
That means the only option i have is to pass this third party component
instance to a method, i hope this is possible, even if it is, how do i define
the 'xyz' data type in the idl file?
<br />
import "oaidl.idl";<br />
import "ocidl.idl"; <br />
[<br />
object,<br />
uuid(AB375A74-76CB-4BBC-BFED-141791262B38),<br />
dual,<br />
helpstring("IExposedATLClass Interface"),<br />
pointer_default(unique),<br />
oleautomation<br />
]<br />
interface IExposedATLClass : IDispatch<br />
{<br />
[id(1), helpstring("method GetInstance")] HRESULT GetInstance([in] Ixyz *instance);<br />
};<br />
<br />
[<br />
uuid(3C9EB277-EC91-4E42-8CD7-34F918490B69),<br />
version(1.0),<br />
helpstring("MYDLL 1.0 Type Library")<br />
]<br />
library MYDLLLib<br />
{<br />
importlib("stdole32.tlb");<br />
importlib("stdole2.tlb");<br />
importlib("thirdpartycomponent.tlb");<br />
<br />
<br />
[<br />
uuid(4DC3999A-797D-4F9A-8955-812E87E4B6D0),<br />
helpstring("ExposedATLClass Class")<br />
]<br />
coclass ExposedATLClass<br />
{<br />
[default] interface IExposedATLClass;<br />
};<br />
};<br />
the compiler doesnt recognize the xyz data type...
i import the component(OCX) in my stdafx.h file, my idl file imports the midl compiler generated .tlb file in my library namespace, after all this when i try importing the component's idl file in my idl
<br />
import "oaidl.idl";<br />
import "ocidl.idl"; <br />
import "thirdpartycomponent.idl";<br />
the compiler reports ambiguous symbols.
what should i do?
I'd really appreciate any kind of help/suggestion here.
nikhil
|
|
|
|
|
Hi all -
I can't find the hash_map file in VC6 STL include folder. Could somebody give me exact link from MSDN to download the ext folder, which contains this hash_map file?
Thanking in anticipation..
Misha
|
|
|
|
|
STL in VC6 doesn't have hash_map. At all. Not even a download from MSDN. You could a) find a third party implementation that you can drop in (I don't know of one), b) use STLport[^] (free) rather than the DinkumWare STL that comes with VC6, c) buy and use the (not free) DinkumWare[^] Standard C++ Library (this is a newer version of the one that comes with VC6) or d) upgrade to VC7.1 (VS2003), although I'm presuming that's not an option.
|
|
|
|
|
The Boost.MultiIndex library can do this and much more besides.
Steve
|
|
|
|
|
Hi,
I have a WTL app in which i have a property page based on CPropertyPageImpl.
On that page i have a Static Text Control which is basically sample of the text selected and thus labeled IDC_SAMPLE.
no i mapped WM_CTLCOLORSTATIC using MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic)in a BEGIN_MSG_MAP_EX. and my implementation is a s follows :
LRESULT CItemAppearanceOptsImpl::OnCtlColorStatic(HDC hDC, HWND hWnd)<br />
{<br />
long lWndID = ::GetWindowLong(hWnd, GWL_ID);<br />
if (lWndID == IDC_SAMPLE)<br />
{<br />
::SetBkMode(hDC, TRANSPARENT);<br />
::SetTextColor(hDC, m_cfb->GetBarItemColor());<br />
::SetBkColor(hDC, ::GetSysColor(COLOR_BTNFACE));<br />
if (m_returnBrush) m_returnBrush.DeleteObject();<br />
m_returnBrush.CreateSysColorBrush(COLOR_BTNHIGHLIGHT);<br />
SetMsgHandled(TRUE);<br />
return (LRESULT)m_returnBrush.m_hBrush;<br />
} <br />
else<br />
{<br />
SetMsgHandled(FALSE);<br />
if (m_returnBrush) m_returnBrush.DeleteObject();<br />
m_returnBrush.CreateSysColorBrush(COLOR_BTNFACE);<br />
return (LRESULT)m_returnBrush.m_hBrush;<br />
}<br />
}<br />
m_returnBrush is a CBrush defined in the header and set at OnInitDialog to COLOR_BTNFACE.
now if i change the single line
m_returnBrush.CreateSysColorBrush(COLOR_BTNHIGHLIGHT);
to m_returnBrush.CreateSysColorBrush(COLOR_BTNFACE);
no change in color occurs - i.e meaning that it doesn`t work.
any ideas why? using COLOR_BTNHIGHLIGHT gives it a different look than the rest of the Page and I want a uniform UI.
thanks in advance.
|
|
|
|
|