|
You aren't serious are you? This is elementary C++ programming. I strongly suggest you find a beginner C++ book and read it.
In the meantime, these are overloaded functions. And the asterix means that the object being passed/returned is a "pointer." (I now feel like Dr. Evil explaining the obvious.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
i need help: when i compile the following program (I have tested in bloodshed devc++, and visual c++ .net):
---------------------------------------------------------------------------
#include <fstream>
#include <iostream>
#include <windows.h>
#include <float.h>
using namespace std;
int main()
{
float fnumber=1.123456789012345678;
double dnumber=1.123456789012345678;
long double ldnumber=1.123456789012345678;
cout << "Float: " << fnumber << endl;
cout << "Double: " << dnumber << endl;
cout << "Long Double: " << ldnumber << endl;
cout << "sizeof(float): " << sizeof(float) << endl;
cout << "sizeof(double): " << sizeof(double) << endl;
cout << "sizeof(long double): " << sizeof(long double) << endl;
system("pause");
return 0;
}
----------------------------------------------------------------------------
, the program outputs fnumber, dnumber and ldnumber (all of them) as 1.2346.
i have no clue why this is happening... i am running this program on a athlon xp 2000+, under windows xp pro sp1...
any help will be aprecciated...
|
|
|
|
|
the preprocessors are iostream, float.h, windows.h (i forgot about html tags on the forum...)
|
|
|
|
|
The default precision is the same for all floating-point types. Use the setprecision() manipulator or cout::precision() function to change the number of displayed digits.
|
|
|
|
|
You need to tell cout that you want to see more digits than the default (six I think) is:
[...]
long double ldnumber=1.123456789012345678;
cout.precision(20);
cout << "Float: " << fnumber << endl;
[...].
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Hello, I was wondering if a macro within a .dsm macro file (for use in VC++6.0)can call a function that resides in another .dsm file? If so, what would the code be? Thanks.
|
|
|
|
|
Hi,
I posted about this a few days ago, but didn't get anywhere with it. I have a MFC DLL that I wrote to access a database that I'm using with my program (also MFC).
What I've been doing is in each function I have in the dll, I connect to the database, perform the operation I want and then disconnect. This worked perfectly fine. However, I decided it was a waste of processing time to connect and disconnect each time I accessed the database, so I wrote two functions called connect and disconnect in order to be able to hold onto the database connection for the life of the program.
This is how I did it.
CDatabase database;
__declspec(dllexport) void Connect()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
database.Open( "EmployeeManager" );
}
__declspec(dllexport) void Disconnect()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
database.Close();
}
This seems to me that it would work without problems. However, when I try to close the program it causes an error that says "A Breakpoint has been reached" and it crashes.
All I did was override OnClose and call disconnect before I close. I stepped through the debugger and it doesn't crash on disconnect, but right after the close is executed. There are no breakpoints anywhere in the program so I have no idea what's going on here. Can anyone help me out?
Thanks,
Mike
|
|
|
|
|
Mike Danberg wrote:
__declspec(dllexport) void Disconnect()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
CDatabase database;
database.Close();
}
Here you are closing an unopened database, as CDatabase is local to the function. This makes no sense what so ever. If you are trying to close the database opened in Connect, then you will have to make database a global variable rather than being local to the two functions.
Michael
'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space
|
|
|
|
|
Oops. I posted the wrong code. Sorry. That CDatabase database shouldn't be in there. I don't remember why I put it there, probably just so it would compile without a problem.
Anyway the code I had, uses a global variable, and it was crashing on close. Looked like this.
CDatabase database;
__declspec(dllexport) void Connect()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
database.Open( "EmployeeManager" );
}
__declspec(dllexport) void Disconnect()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
database.Close();
}
Mike
|
|
|
|
|
I have some C code here, my teachers, that I'm trying to rifle through and figure out. I am confused on on line of it: The second line down is
*b = (int*) malloc ( n * sizeof(int));
does this mean a integer pointer that point to a memory location that is 4 times the size of an integer? Which would be then 16 bytes. So a int pointer that points to 16 bytes of vacant memory. Am I right, close or way off.
Please help. the code below is what it is out of.
Thanks for your help.
#include "stdio.h"
void ByteSwap4_c(int n, int *a);
void ByteSwap4_asm(int n, int *a);
void ByteSwap4(int n, int *a)
{
int i;
int *b = (int*) malloc ( n * sizeof(int));
for (i=0; i<n; ++i)
b[i]=a[i];
ByteSwap4_asm(n,a);
ByteSwap4_c(n,b);
for (i=0; i<n; ++i)
{
if (a[i] != b[i])
{
printf("a[%d] (0x%08X) != b[%d] (0x%08X)\n",i,a[i],i,b[i]);
exit(1);
}
}
free(b);
}
void test4(int n, int *a, int *b)
{
int i;
ByteSwap4(n,a);
for (i=0; i<n; ++i) {
if (a[i] != b[i]) {
printf("a[%d] (0x%08X) != b[%d] (0x%08X)\n",i,a[i],i,b[i]);
exit(1);
}
}
}
int main()
{
static int a[4]={0x01020304, 0xa0b0c0d0, 0xabdcef12, 0x12345678};
static int b[4]={0x04030201, 0xd0c0b0a0, 0x12efdcab, 0x78563412};
test4(4,a,b);
printf("all tests pass\n");
}
void ByteSwap4_c(int n, int *a)
{
int i;
for (i=0; i<n; ++i)
{
int tmp=a[i];
int pmt;
((char*)(&pmt))[3]=((char*)(&tmp))[0];
((char*)(&pmt))[2]=((char*)(&tmp))[1];
((char*)(&pmt))[1]=((char*)(&tmp))[2];
((char*)(&pmt))[0]=((char*)(&tmp))[3];
a[i]=pmt;
}
}
|
|
|
|
|
The malloc() call allocates space for a table of n integers.
|
|
|
|
|
noobie
Don't try it, just do it!
|
|
|
|
|
The first time when it does work look at the stack backtrace and follow the calls back the MRU code. Then set a breakpoint on the code that handles the users MRU file menu selection. Then pick another item from the MRU list and follow what happens when the first breakpoint is reached.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi,
thanks for the reply.
i am not sure i understand your comment. why does the OnOpenDocument method is not being called for the second time i am trying to open the same MRU?
do i need to set a flag or something?
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
YaronNir wrote:
why does the OnOpenDocument method is not being called for the second time i am trying to open the same MRU?
Good question.
YaronNir wrote:
do i need to set a flag or something?
No.
Set a breakpoint on CWinApp::OnOpenRecentFile() and see what is going wrong. It calls OpenDocumentFile() ....
Hope that helps.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Ok,
i got into the core of the code. look at this:
CDocTemplate::Confidence CDocTemplate::MatchDocType(LPCTSTR lpszPathName,
CDocument*& rpDocMatch)
{
ASSERT(lpszPathName != NULL);
rpDocMatch = NULL;
POSITION pos = GetFirstDocPosition();
while (pos != NULL)
{
CDocument* pDoc = GetNextDoc(pos);
if (AfxComparePath(pDoc->GetPathName(), lpszPathName))
{
rpDocMatch = pDoc;
return <big>yesAlreadyOpen</big>;
}
}
CString strFilterExt;
if (GetDocString(strFilterExt, CDocTemplate::filterExt) &&
!strFilterExt.IsEmpty())
{
ASSERT(strFilterExt[0] == '.');
LPCTSTR lpszDot = _tcsrchr(lpszPathName, '.');
if (lpszDot != NULL && lstrcmpi(lpszDot, strFilterExt) == 0)
return yesAttemptNative;
}
return yesAttemptForeign;
}
this method returns (as i looked at the break point) "yesAlreadyOpen"
that is why nothing happens for me....
i still think i need to set a flag or something....
can u help ???
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Are you sure the document is actually being closed. It doesn't sound like it from what you're saying. Have a look at the pDoc that it is matching on. See if it has any views attached. I think there is a count you can see by looking at the CDocument. Or maybe you have other views besided the SDI view?
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I think you are right,
but what am i missing in the close documents???
this is the code for the close request, i differ between 2 things
void CMyDoc::OnCloseDocument()
{
((CMainFrame*)AfxGetMainWnd())->OnFileClose();
if (((CMainFrame*)AfxGetMainWnd())->m_bCloseRequest)
CDocument::OnCloseDocument();
}
this is what i do in CMainFrame::OnFileClose() :
void CMainFrame::OnFileClose()
{
CMCEditorView* pView = (CMyView*)GetActiveView();
pView->ClearListCtrl();
SetWindowText(_T("My application - Untitiled"));
}
i differ between a closing application request and closing document request....the latter is just initializing the list control i have and set the title to be "untitled" and the first close the application.....
what am i missing?
thanks for all the help so far...
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Doesn't it simply come down to how: m_bCloseRequest is set. I don't think this is part of MFC, so it is a variable you are managing.
I certainly think that having CMyDoc know about and access CMainFrame is not good design. It should be the other way around. ie. Code in CMainFrame should call whatever CMyDoc etc. functions necesessary.
End of another long day of coding, so you won't hear any more from me until tommorrow.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
thanks for the design tip, i completely agree with you.
the m_bCloseRequest is something i manage.if i won't use a flag in the OnCloseDocument, then when i will choose from the menu 'File-->Close' the application will exit (i am using SDI).
that is why i needed that flag......
still i don't know how to solve my problem.....any other suggestions?
have a good night.....
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hi Yaron,
I'm a little confused about what the problem is now. I suggest you start a new thread, which outlines the problem as you now know it.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I have an MFC application (VC6) which does not close correctly. Its an doc/view application. When I exit application the window was closed, but the process was not terminated. In debugger I have to stop debugging. In taskmanager I can see my application that should be closed.
I have set some breakpoints but they never arrived. E.g. I try ExitInstance.
Any idea where I can looking for?
|
|
|
|
|
First if you are using W98 etc. I'd restart Windows. Then set a breakpoint on CMainFrame::OnClose() and try again.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanx for answer.
I have Win2000. After restart I have same behaviour.
I set a breakpoint on CMainFrame::OnClose(). This breakpoint was reached. I set breakpoint on ~CMainFrame. This breakpoint was reached too.
After stopping debugger and stepping through code I went into CWinThread::PumpMessage(). I had to break the debugger to leave the application.
|
|
|
|
|
Would it be because there are still some of your process's thread running somewhere?
Sonork 100.41263:Anthony_Yio
|
|
|
|