|
That is incorrect. The following two lines are exactly the same
No they are not. My post explains it in pretty much detail.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
*shrug* Try it yourself. 'string s = "abc"' has nothing to do with the copy constructor or the = operator.
--Mike--
"There are three things I can never remember, 1: um... 2: um... 3: um..."
-- Victor Borge
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
I did! Try the following (please bare with typos, I'm writing this without IDE support):
class A
{
public:
A(const char *)
{
}
private:
A(const A&);
};
int main()
{
A a="hello";
return 0;
} Under default settings, whis will compile fine and actually only A::A(const char*) is being invoked. However, if you set the /Za flag (disable MS proprietary extensions to C++), then an error pops up complaining that the copy ctor is not accessible and thus, by the rules of C++, optimizing it away is not legal. This is called elided copy constructor, and there's a paragraph in the standard dealing with the issue. Also Stroustrup in The C++ Programming Language, Special Edition states the sequence of calls for an expression of a form analogous to this in an example. If you're interested I could try to locate the exact paragraph for you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
kilowatt wrote:
By calling:
string s1 = "the truth is out there";
you are first invoking the default constructor
That is incorrect. The following two lines are exactly the same:
string s1 = "the truth is out there";
string s1 ("the truth is out there"); They both call the one-parameter constructor.
--Mike--
"There are three things I can never remember, 1: um... 2: um... 3: um..."
-- Victor Borge
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Not exactly. If you like C++ standard subtleties, please take a look at my post above.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
What message should my app handle when user shutdown/logoff the system?
thanx
|
|
|
|
|
The system will send a WM_QUERYENDSESSION message to all of the applications asking if it is OK to shutdown windows, if any one of them returns false, then windwos will quit shutting down.
After the system sends the WM_QUERYENDSESSION message, your app will receive a WM_ENDSESSION message indicating whether or not windows is actually going to shut down and your app should shut down.
|
|
|
|
|
Thanx ,
Where should i handle that ?
|
|
|
|
|
Handle it in your main window , WindowProc function, this is the window that it gets sent to.
|
|
|
|
|
|
Does anyone know if it is possible to login to a winNT box from over a network. I.E the other computer is at its login screen therefore standard screen sharing programs cannot be used as I think they require a server to be running on the unlogged in machine.
Thanks
Coremn
---------
I sig there for I am
(not an animal!!!)
|
|
|
|
|
Windows NT terminal server will do this, as will "VNC", provided you "install vnc as a service"
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I am trying to create an example using for_each to delete objects where they are stored in a container as pointers. I have this:
class pType
{
public:
pType::pType()
{
cout << "Constructor\n";
}
pType::~pType()
{
cout << "Destructor\n";
}
};
template <class T> void ptrErase(T * type)
{
delete type;
};
in main()
vector <pType *> vecpType;
for (i = 0;i < 20; ++i)
{
pType * pInt = new pType;
vecpType.push_back(pInt);
}
for_each(vecpType.begin(), vecpType.end(), ptrErase<pType>);
I get a linker error,
STL.obj : error LNK2001: unresolved external symbol "void __cdecl ptrErase(class pType *)" (?ptrErase@@YAXPAVpType@@@Z)
Debug/STL.exe : fatal error LNK1120: 1 unresolved externals
I am not as familiar with templated functions as I would like, could someone tell me what I am doing wrong pls ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Change this:
template<class T>
void ptrErase(T * type)
{
delete type;
};
to this:
template<class T>
struct ptrErase : public unary_function<T, void>
{
void operator() (T type)
{
delete type;
}
};
because the for_each function requires a function object rather than a simple function.
The operator() allows you to call the name of your object, just like it were a function call.
|
|
|
|
|
Thanks - I had contemplated that this might be the problem after posting, but I was hoping not for ease of readability ( it's a beginners tutorial after all ).
This works great - thanks again.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Some of the features in STL, and C++ for that matter, are convoluted, and I think that is what shys alot of people away from these features in the first place. This is a shame because learning some of these techniques can lead to very elegant solutions.
|
|
|
|
|
In case you wonder, your original code should have worked, but it doesn't due to a limitation of VC++ --it lacks support for so called explicit instantiation of template functions, or better stated, its support is broken. Don't know the status of this bug in VC++ 7.0.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Have a little question for you all. In regards to STL -- what distribution of it do you use? (assuming that you use it of course).
Visual C++ 6 has STL support (to a point), it seems incomplete though. I downloaded and started using the SGI STL which is complete (except I found that it only supports the depricated <iostream.h> not the new <iostream> .. what the heck is going on?
I'm a little confused .. maybe I'm just not seeing some obvious small detail here ..
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
I prefer the SGI STL implementation.
A while back I created a test program to compare STL versus MFC's container classes, and MFC's classes kicked butt over STL, that is the STL that is included with DevStudio. Then I recompiled the program with SGI's version and the competition was feirce depending on the way that the container was used. Sometimes STL was more efficient, others it was MFC container classes, which is to be expected.
The SGI implementation supports other classes that I don't think are in the standard yet. One of my favorite classes in the SGI implementation is the hashmap and hashset, this is used in the exact same way that the map and set are used, but the underlying representation is a hash table rather than a table.
I could not find what you were talking about between depricated and new, could you give more details on that?
|
|
|
|
|
What I meant was that (this is only one instance), the SGI STL has been designed to support the old header file naming style. That is, you would include iostream.h <-- rather than iostream -- if you do include iostream so you can access the new features you will get a lot of errors because it doesn't handle it yet for some reason.
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
sgi STL is not being built upon, hence the deprecation problem. Use STLPort instead - www.stlport.com, it has the hash table, the additional modifiers, etc., in fact everything the SGI STL has and more.
I believe VC.NET has a better STL - previously they have been stuck with an old Dinkumware implimentation for purely legal reasons.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
I just downloaded STLport and am reading about it's use.. thanks for the suggestion.
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
Hi,
I have an SDI application that has a CFormView derived class as well as a docking window with a CDialog derived class. When the user clicks on the Print command, the message goes to the CFormView derived class where I modified the CFileDialog with two radio buttons to either print the main CFormView or the CDialog window.
Well, when I do this and I call the CDialog derived printing code for some reason, the document gets printed three times and then throws an exception. In actuallity, it should only print one page, I also tried setting the max page to 1 to no evale. I can't figure out why this happens, I guess it could be because the CFormView class is processing the print call but I'm not sure.
Does anyone have any suggestions on how I can fix this peculiure problem?
Thanks in advance,
Craig
|
|
|
|
|
I would recommend emulating the Doc?view printing procedure for your dialog derived class. I did something similar when printing to PDF files. The whole code for that procedure here is shown, so some of the code will not be relevant to what you are doing, but it will give you some idea of how to progress:
DOCINFO di ;
CPrintInfo printInfo ;
CRefinementProDoc *pDoc = GetDocument() ;
CString filename ;
CDC dc ;
CRect draw_area ;
ASSERT_VALID(pDoc) ;
filename = pDoc->GetPathName() ;
filename.MakeLower() ;
if (filename == "")
{
filename = pDoc->GetTitle() ;
if (filename.Find(" (modified)") >= 0)
filename = filename.Left(filename.GetLength() - 11) ;
}
if (filename.Find(".sds") >= 0)
filename = filename.Left(filename.GetLength() - 4) ;
if (filename.Find(".mds") >= 0)
filename = filename.Left(filename.GetLength() - 4) ;
filename += ".pdf" ;
CFileDialog dlg(FALSE, "PDF", filename, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, "Adobe acrobat PDF files (*.pdf)|*.pdf||") ;
dlg.m_ofn.lpstrInitialDir = theApp.g_szLastDirectory ;
pView = this ;
dlg.SetTemplate("MYFILEOPEN", "MYFILEOPENEXPLORER") ;
dlg.m_ofn.Flags |= OFN_ENABLEHOOK ;
dlg.m_ofn.lpfnHook = (LPOFNHOOKPROC)OFNHookProcOldStyle ;
if (dlg.DoModal() == IDCANCEL)
return ;
for (int i = 0 ; i < MAX_DLLS ; i++)
global_page_status[i] = g_bAllowPrint[i] ;
filename = dlg.GetPathName() ;
HDC hDC = theApp.g_PDF.GetPrinterDC() ;
if (hDC == NULL)
return ;
OnAboutToPrint() ;
di.cbSize = sizeof(DOCINFO) ;
di.lpszDocName = pDoc->GetPathName() ;
di.lpszOutput = filename ;
dc.Attach(hDC) ;
printInfo.m_bDirect = TRUE ;
printInfo.m_rectDraw.left = 0 ;
printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES) ;
printInfo.m_rectDraw.top = 0 ;
printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES) ;
draw_area = printInfo.m_rectDraw ;
dc.StartDoc(&di) ;
OnPreparePrinting(&printInfo) ;
for (printInfo.m_nCurPage = 1 ; printInfo.m_nCurPage <= printInfo.GetMaxPage() ; printInfo.m_nCurPage++)
{
dc.StartPage() ;
OnPrint(&dc, &printInfo) ;
dc.EndPage() ;
printInfo.m_rectDraw = draw_area ;
}
OnEndPrinting(&dc, &printInfo) ;
dc.EndDoc() ;
VERIFY(dc.DeleteDC()) ;
if (theApp.g_bStartPDF)
ShellExecute(NULL, NULL, filename, NULL, NULL, SW_SHOWMAXIMIZED) ;
theApp.SetLastDirectory(filename.Left(filename.ReverseFind('\\'))) ;
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
|
|
|
|
|
Roger,
Thanks so much for your example, I will try it and see if it will solve the problem I am having.
Thanks again,
Craig
|
|
|
|