|
manustone wrote: template <class T>
ostream& operator<>(ostream& os,CNeuron<T>& obj)
{
os <> obj.list_of_obj[0] <> endl;
os <> obj.list_of_obj[1] <> endl;
os <> obj.list_of_obj[2] <> endl;
os <> obj.list_of_obj[3] <> endl;
return os;
}
This will not compile if T is string .
I can run your original code with these changes, But that will not solve your purpose.
template<class T>
class CNeuron{
public:
CNeuron( const T obj ) {list_of_obj.push_back( obj );}
~CNeuron()
{
list_of_obj.pop_back();
}
friend ostream& operator <<(ostream& os, CNeuron<T>& obj)
{
see for over loaded operator << for class T,
in your case T is string, not having operator <<.
return os;
};
private:
vector<T> list_of_obj;
};
void main()
{
Neuron<string> n("ciccio");
cout << n << endl;
CNeuron<int> n2(20);
cout << n2 << endl;
}
|
|
|
|
|
You are right!!!
Get rid of my first comment becasue it's true: I was using 2 different function.
If I put inside the class the same signature everything turns ok.
For my class I need to use this:
template <class T>
friend ostream& operator<<(ostream& os,CNeuron<T>& obj);
and the result is a wonderful super templatized function for streaming out!!!
Many thanks for your help!!!
regards
ManuStone
|
|
|
|
|
|
hi all
I'm newbe to STL and function templates.
I wrote this simple function and I expected to print a result to screen, but instead I've got an error. Why does this happen?
template<class T>
T Minimum(T a, T b)
{
cout << "Minimum by T" << endl;
return (a < b);
}
void main()
{
string a("StrA");
string b("StrB");
cout << Minimum( a,b ) << endl;
};
Regards
manuStone
|
|
|
|
|
The return type of Minimum() should be bool , no?
|
|
|
|
|
You should look at the error. Min/Max functions tend to return the min/max value evaluated while less/more return a boolean comparison of the two values.
template<class T><br />
bool Minimum(T a, T b)<br />
{<br />
cout << "Minimum by T" << endl;<br />
return (a < b);<br />
}
or
template<class T><br />
T Minimum(T a, T b)<br />
{<br />
cout << "Minimum by T" << endl;<br />
return (a < b) ? a : b ;<br />
}
m.bergman
-- For Bruce Schneier, quanta only have one state : afraid.
|
|
|
|
|
Many Thanks for your resposne
ManuStone
|
|
|
|
|
I have a custom tool bar which is inherited form WTL toolbar. In my tool bar I have a custom OnPrePaint paint function where I give custom texture for the background of the toolbar.
class CCustemToolBar : public CWindowImpl<ccustemtoolbar,ctoolbarctrl>,
public CCustomDraw<ccustemtoolbar>
It works fine. No problem.
Now I added Slider to bar. It shows perfect. Now if I resize me window the toolbar also updates and the Slider disappears. To sea the Slider I have to bring my mouse on the indicator (Just by guess) and it redraws it, but it does not draw the indicator sliding line. In other words after redrawing the toolbar the Slider does not update. I just run out the ideas what to do, even I tried not to paint that Slider window, which produces a black rang tangle. Any idea? You help will be very much appreciated.
Best regards,
Agha Khan
Agha Khan
|
|
|
|
|
I have a COM/ATL out-of-proc server whose main object is a singleton. I will call this Object A. Object A is called by other out-of-proc servers, but they are on the same machine so I am not worried about DCOM, etc. Object A uses a third party library (another set of COM objects) which generally works well but has a couple of known problems which can crash the Object A server (the problem can be reproduced). I have isolated this library into its own out-of-proc server to protect the Object A server. The library of the new server contains an object (I will call it Object B) which gets a reference to Object A. Object A releases its reference to Object B, but Object B maintains its own reference until its work is done. When the work by Object B is done, it notifies Object A, releases Object A and then releases itself. When all other servers are done and release Object A, then Object A is released and goes away normally.
If in the middle of its work, Object B crashes, it takes down its own server but the server which owns Object A is unharmed... except, that it still thinks there is another server out there which has a reference to it, so it won't shut down when all other out-of-proc servers have released their references.
Object A also maintains a watch on the Object B process so it knows if the Object B process has crashed.
Efforts to decrement the interface count on Object A when Object B crashes were not helpful and could have caused other problems (the reference count in Object A does not appear to be affected by Object B... I am assuming an internal reference count and an external referece count... but if so, where is the external reference count stored and can it be decremented???).
Ultimately, I need to get Object A back to the state it had before it created Object B.
I am also posting this in the COM forum.
Thanks.
m.bergman
-- For Bruce Schneier, quanta only have one state : afraid.
|
|
|
|
|
Hi
I am getting Access violation whenever I Query for IWMSBufferAllocator in my custom plugin.
Here is code
<br />
IWMSBufferAllocator *pBufAllocator = NULL;<br />
<br />
if(m_spClassFactory)<br />
{<br />
hr = m_spClassFactory->QueryInterface(IID_IWMSBufferAllocator,(void**)&pBufAllocator);<br />
if(FAILED(hr))<br />
return hr;<br />
}<br />
Debug output gives these lines
Access violation reading location 0xfffffffffffffff.
The thread 'Win64 Thread' (0x338) has exited with code 0 (0x0).
First-chance exception at 0x78d67d0d in WMServer.exe: 0x80010105: The server threw an exception.
m_spClassFactory seems good. Its not a null or invlaid pointer. I have also tried with code like MSDN where
hr = m_spClassFactory->QueryInterface(IID_IWMSBufferAllocator,(void**)&pBufAllocator);
is used as
hr = m_spClassFactory->QueryInterface(&pBufAllocator);
Can someone help? There is no other doc available.
-----------------------------
In my dream, I was dorwning my §orrow§
But my §orrow§, they learned to §wim
|
|
|
|
|
Hi All,
I'm embarrased to ask this one, but for the life of me, I don't see what I am doing wrong...
I've gone as far as making the default ctor private, removing all ctors, removing all copy ctors, explicit ctors, etc. I've even changed the declaration fro char* s to char s[] .
Jeff
#include "stdafx.h"
#include <string>
#include "SecureString.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s1 = "Hello World";
SecureString ss1 = "Hello World";
return 0;
}
#include <string>
#include <locale>
class SecureString : public std::basic_string< char,
std::char_traits<char>, CryptoPP::SecByteBlock >
{
public:
SercureString( char* s ) { operator=( s ); }
SecureString& operator=( char* s )
{ assign( s ); return *this; }
~SecureString( );
operator const byte*() { return reinterpret_cast<const byte*>( this->data() ); }
private:
SecureString();
};
|
|
|
|
|
Jeffrey Walton wrote: SercureString( char* s ) { operator=( s ); }
This c'tor should remove error message. Though, I'm confused with its definition in your code.
|
|
|
|
|
Hi Prasad,
Thanks, but no joy...
I've since tried forcing the "\TP" switch, breaking out the *.h file into a 'h' and 'cpp' file, etc. I also made it a basic class (no inheritance). I've got the damn thing reduced to a class with 1 ctor - the char*. It's also broken for me (or more correctly, I'm doing something wrong) with VS 8.0 - previous was 7.0.
I alsoe get missing return type with ctor: SercureString( const char* s ); .
Is the name "SecureString" used by VS? Earlier this week I installed the DDK. Could this be it???
Jeff
#pragma once
class SecureString
{
public:
SercureString( const char* s );
~SecureString( );
private:
SecureString();
};
SecureString::SecureString( const char* s )
{
}
|
|
|
|
|
Jeffrey Walton wrote: I alsoe get missing return type with ctor: SercureString( const char* s );.
Nice to see that your problem got solved. But, your class name was SecureString , not SercureString , wasn't that ?
You tried to declare your c'tor with wrong name. Thats why error regarding missing return type was there.
|
|
|
|
|
Hi Prasad,
prasad_som wrote: Nice to see that your problem got solved.
Yes - finally.
prasad_som wrote: your class name was SecureString, not SercureString,
I thought I cleaned up the typo this morning...
Jeff
|
|
|
|
|
Changing "SecureString" to "SecString" resolved the issue...
|
|
|
|
|
Change SecureString(char* s) to SecureString(const char* s) - there's no reason to not have the param be const . Then make the same change in the corresponding operator=
|
|
|
|
|
Hi Mike,
Thanks, but no joy...
I've since tried forcing the "\TP" switch, breaking out the *.h file into a 'h' and 'cpp' file, etc. I also made it a basic class (no inheritance). I've got the damn thing reduced to a class with 1 ctor - the char*. It's also broken for me (or more correctly, I'm doing something wrong) with VS 8.0 - previous was 7.0.
I alsoe get missing return type with ctor: SercureString( const char* s ); .
Is the name "SecureString" used by VS? Earlier this week I installed the DDK. Could this be it???
Jeff
#pragma once
class SecureString
{
public:
SercureString( const char* s );
~SecureString( );
private:
SecureString();
};
SecureString::SecureString( const char* s )
{
}
|
|
|
|
|
Changing "SecureString" to "SecString" resolved the issue.
I wish I would have tried it before removing the DDK...
Thanks for the help.
Jeff
|
|
|
|
|
Before you settle with SecString , please be aware that your original code had a mispelling at the char * constructor, you wrote SercureString rather than SecureString . Could it be this was the problem in the first place?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hi,
I have an Atl Component with an Interface EFCMyForm .(ATL Simple Object -- VS2005)
And a Dialog class CMydialog with ActiveX controls Placed on it. using right Click on Dialog and Insert ActiveX Control
In One of thw Exposed Method I am creating the dialog box CMyDialog
CMydialog g_myDlg;
STDMETHODIMP CEFCMyForm::Create()
{
#ifdef _AFXDLL
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif
g_myDlg.Create(IDD_MY_DLG);
}
If I take a Global variable I don't have any problem but if I take mydialog obj as member variable as shown below...
CMydialog m_myDlg;
STDMETHODIMP CEFCMyForm::Create()
{
#ifdef _AFXDLL
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif
m_myDlg.Create(IDD_MY_DLG);
} then the ActiveX Controls which are placed on the Dialog are not being Shown.
To resolve this If I try to Dyanamically create the ActiveX controls
CMyDialog::OninitDialog(){-----Using Create Control------ CLSID clsid;
HRESULT hr1 = CLSIDFromProgID(OLESTR("EsdGraphCtrl.EsdGraphControl.3.0"),&clsid) ;
if (FAILED(hr1)) { return FALSE; }
BOOL blnSuccess; CRect rc; rc.left=0; rc.top=0; rc.right= 100; rc.bottom =100;
blnSuccess = m_AxGraphControl.CreateControl(clsid,_T("Graph"),WS_VISIBLE|WS_CHILD,rc,this,100,0,0,0);
if (!blnSuccess)
{ return FALSE; }
}
Any Suggestions would be helpful
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
Hi,
I want to write an activeX control that allows an event to be processed in the container class itself.
So what I want to do is have the ActiveX Control trigger say a Visual Basic Application when data is available. I am looking at ATL to write this, and I was wondering if this is possible with ATL.
If it is, does someone have some simple same code or something to assist me, I am brand new to ATL.
Thanks in advance for any help.
|
|
|
|
|
godspeed123 wrote: I was wondering if this is possible with ATL
Absolutely.
Have a look at ATL examples in MSDN here[^] and as always; CodeProject is a good place to start, e.g. this article[^].
You might also want to browse through the other CP articles in the COM section[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
step 1 : define a class "CMyListViewImpl ".
typedef CWinTraitsOR "WS_BORDER | LVS_REPORT | LVS_SINGLESEL |
LVS_NOSORTHEADER | LVS_SHOWSELALWAYS" CListTraits;
class CMyListViewImpl :
public CWindowImpl "CMyListViewImpl,CListViewCtrl,CListTraits"
//(here " is supposed to "<" and ">", web page can't show "< >" ,
//so i write " after CWindowImpl and CWinTraitsOR )
{
...
};
step2 : in SDI CMainFrame. define a data member "CMyListViewImpl m_list;"
step3 : create listview control :
CMainFrame::OnCreate()
{
...
m_list.Create(m_hWnd,rcDefault);
m_list.InsertColumn ( 0, _T("Macro"), LVCFMT_LEFT, 120, -1 );
m_list.InsertColumn ( 1, _T("Result"), LVCFMT_LEFT, 90, -1 );
m_list.InsertItem(0,_T("1"));
m_list.SetItemText(0,1,_T("D"));
m_hWndClient = m_list ;
}
the creation procedure are listed above,but i can't see the listview .where the bug lies ?(WTL 7.1 ,vc6 )
|
|
|
|
|
Did you call AtlInitCommonControls() ?
|
|
|
|
|