|
class node{
public:
//the following will take care of a=b problem
node& operator = (const node & other) : k(other.k), l(other.l){}
int k;
ink l;
};
void main(){
node *master;
node *tmp;
tmp=master;//this is wrong
//1. both pointers uninitialized
//2. even if they were initialized(“p = new node;”), you just lost the pointer to tmp. tmp points to the same object as master now
tmp->k=10; //master->k also change to 10 // since tmp points to master now, it is not surprising changes to tmp are actually changes to master
/////////////
node a;
node b;
// the following is not a problem anymore
a=b; //ERROR : no opearator found witch takes a right-hand operand of type node
}
I would strongly recommend to read something about pointers. Something as bacis as Kernighan and Ritchie.
|
|
|
|
|
realy thanks. u explained me all of the problems of the code. i get what ever u said and i will use them in the code. thanks again
|
|
|
|
|
Hi all, I'm writing my own string library that needs to be super-fast (much faster than CString). I am well on the way but need an efficient way of allocating memory so that I don't get fragmentation when concatening strings etc. I have thought of a way for an allocation routine to do this whereby memory is always allocated as a base 2 block with the minimum being 8 bytes. This will allow the string to grow in size with little fragmentation on reallocation (and indeed less use of realloc). It will of course, always consume slightly more memory than is required to hold the string. All I need is a method for grabbing the highest order bit that describes the length of the string and bit shift it to the left e.g. say the string was "LENGTH" it is 6 chars long so the highest bit is (0100 - since 6 is 0110 in binary) and bit shift it to 1000. I would then malloc 8 bytes which is enough to hold the 6 char string and its 1 char null terminator. However, I'm stuck on finding the quickest method of getting the highest ranking bit. I know I can do it by testing 0100 & 1000, 0100 & 0100 etc. till I find a match, but I was just wondering if there is a better way? Any comments or suggestions on how to make a better string library would also be grateful.
Alan.
P.S. Also I notice that CString displays the actual string in the variable pane of the debug window, whereas mine displays {...} and you have to go to the next level to check what the string is, any ideas on how I can get it to display {"LENGTH"} would be brilliant too
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
Follow this link[^] for a routine based on succesive approximations.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello Joaquin, its been a while... . Thanks for the URL, you missed out one directory shift by mistake though it should have been ftp://cap.connx.com/pub/bitcount/LOGS/LOG2.C[^] ?
Many Thanks,
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
Ummm. Both URLs point to different files. Yours is based on conversion to double , mine on binary search. Try again, I've just tested the URL and is working OK.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
P.S. Also I notice that CString displays the actual string in the variable pane of the debug window, whereas mine displays {...} and you have to go to the next level to check what the string is, any ideas on how I can get it to display {"LENGTH"} would be brilliant too
This can be done by tweaking a file called autoexp.dat living somewhere inside the installation dir of Visual Studio. Check Oskar Wieland's article CStringW and CStringA
[^] for an example.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks very much Joaquin, this code will cut down my development time immensely! Thankyou. I am looking into the autoexp.dat file thing so hopefully I'll be able to see whats in the string a bit easier too.
Many Thanks (again)
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
sometime i must add the Variable in dialog,but sometime i don't need
why?
which control need add variable and which not?
please tell me, thanks!
Joise is a C++ fun!
|
|
|
|
|
It depends on the control. None of the controls "need" a member variable attached, however it does make life much easier when it comes to accessing the controls from your code.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I copy files a.txt、b.txt and c.txt below C:\ directory to D:\ directory.
if D:\ directory has exists some files just like a.txt,It will pop a "Confirm files replace" dialog to let user choose one of "Ok"、"All"、"No" and "Cancel" button.I want to known which files replace the formerly existing files in the destination directory.
For some reasons, The Precondition is that I must use Windows Shell func
"SHFileOperation", not use "MoveFileEx" or other API.
There are some idea of mine:
1、Get the destination files (that has the same name with one of source
files) attributes, compare the different between them,judge which one
does Replace. to forbid file access collision with other
programmes, "lock" the destination directory utill finish copying
operation.
2、Hook the messages of "Confirm files replace" dialog.
But my trouble is:
for 1:How lock the directory or file? even lock successfully,
the dialog how can replace destination file?
for 2:What is the value of the dialog buttons ID? it is variable
in different OS? how to get the current copying file name?
Can you give me some advice? Any help are appreciated!
C/C++ code fans
|
|
|
|
|
I think if can watch a file do replace and get the operaion thread ID or HANDLE, we will finish the goal, but how to "watch"?
C/C++ code fans
|
|
|
|
|
I have build a simple web browser. It works fine in VS6.0 but when i run the same prog using eVC++ 3.0 the image i am trying to display is all distorted. I figured out that the VS6.0 one works becasue of the command "_setmode( _fileno( fp ), _O_BINARY )" which requires io.h and fctl.h However these header files are not part of the CE SDK. Is there another set of header files that will take care of this problem or is there a work around to it???
I really need some help with this one!!
sparky
|
|
|
|
|
Can't you open the file in binary mode in the first place, instead of changing the mode later?
|
|
|
|
|
I am not entirely sure how to do that in eVC++ considering i need 2 header files that doesnt exist.
This is what i did in VS6 :
"FILE *fp = fopen("c:\\c.bmp", "w+");
_setmode( _fileno( fp ), _O_BINARY );
....code to receive data from socket.....
....write data to file...."
are there equivalent io.h and fcntl.h (under different names ??) in evc++?
sparky
|
|
|
|
|
|
Hello all,
I really have the feeling that this is a stupid question, but for some reason I do not see the answer
Problem (Multi Doc Interface project):
When creating a new document (OnNewDocument), I also need to have access to its ChildFrame object to set some data member (via public method). I used next code, but its unfortunaltely faulty.
<br />
BOOL MyAppDoc::OnNewDocument()<br />
{<br />
if (!CDocument::OnNewDocument())<br />
return FALSE;<br />
...<br />
CMainFrame *pMainFrame = ( CMainFrame* )AfxGetMainWnd(); <br />
ASSERT( pMainFrame ); <br />
CChildFrame *pChild = (CChildFrame *) pMainFrame->GetActiveFrame();<br />
<br />
...<br />
}
Where I'm going the wrong way?
More background info:
In my ChildFrame (not MainFrame) I've defined a statusbar, which should be updated with info I've available at the moment of creation doc (or view).
Thanks in advance,
EiSl
|
|
|
|
|
Perhaps You forgot to call the base class:
BOOL CMyDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// Do initialization of new document here.
return TRUE;
}
The MSDN says that this is called as a part during the File New Command.
You can't be sure that the window already has been completely created.
I did always keep a list of doc/view ptr in min App Object. It worked very well.
<br />
class CMyApp<br />
{<br />
<br />
<br />
public:<br />
vector<CView *> m_ActiveViews;<br />
vector<CDocument *> m_ActiveDocs;<br />
}<br />
<br />
I always filled both in the members in <br />
<br />
void CMyView::OnInitialUpdate( )<br />
{<br />
CView::OnOnInitialUpdate();<br />
<br />
CMyApp *pMyApp = (CMyApp *) AfxGetApp();<br />
if( pMyApp )<br />
{<br />
pMyApp->m_ActiveViews.push_back(this);<br />
pMyApp->m_ActiveDocs.push_back(GetDocument());<br />
}<br />
}<br />
where i could be sure that the window was created and the document ptr
already existing. This would be a better place to change the frame window.
Keep Your list up to date and all will work fine.
<br />
CFrameWnd::InitialUpdateFrame( CDocument* pDoc, BOOL bMakeVisible );<br />
would be the best place to change the frame window behaviour
|
|
|
|
|
Thanks for reply Alois,
I've updated my example since I'm indeed first calling
<br />
if (!CDocument::OnNewDocument())<br />
return FALSE;<br />
after I'm continueing with the rest of my stuff.
More background info:
In my ChildFrame (not mainframe) I've defined a statusbar (at bottom). This one should be updated with information I've available at the 'OnNewDocument' (so the Doc) or in the View. That's the reason I need a pointer to ChildFrame to be able access my CStatusBar member.
Thanks,
EiSl
|
|
|
|
|
Did you try the opposite direction ?
Overide
<br />
CFrameWnd::InitialUpdateFrame()<br />
and get a ptr to your new created document in this function.
There You can safely update your status bar because you can be sure that the
frame window already exists.
I think the problem is that when OnNewDocument is called only the CDocument
is created. The View does not yet exist. The order is if I remember right
first the document then the view with the frame is created. You are trying
to update a frame which does not yet exist.
|
|
|
|
|
hai,
We customized the default open dialog by deriving the class from
cfiledialog . These are the issues that we faced.
Issues:
1. How to handle the default messages in cfiledialog class?
2. In Win'2000 & above, we tried to change the listview style to
LVS_REPORT using Modifystyle method The style is changed, but the files and
column headers are not displayed.
3. In Win'98, how to remove the separator in toolbarwindow32.
Please give me the solution as early as possible.
sureshb
|
|
|
|
|
easiest way to remove separator is to write into the .rc file. open it find the separator and remove the line and you will see you are done. elase you can also modify setting styles.
cheers
Himanshu
|
|
|
|
|
I am writing win32 application.if the application throws any error .how can i handle it.
Any function to handle the error properly.
Thanks in advance.
|
|
|
|
|
u can use c++ native try catch macros or even MFC TRY/CATCH
|
|
|
|
|
Hi,
In my appication i want to check whether the the lbutton is kept pressed.So in my OnLbuttondown() function
i have GetQueueStatus(QS_MOUSEBUTTON || QS_MOUSE || QS_INPUT) it always returns 0 eventhough the left button is down..Can any one tell why is it so?
Regards
Neha
|
|
|
|