|
I am not sure about portability issue but is there any specific reason to do this? These kind of smart-ass statements makes code harder to read and maintain.
-Saurabh
|
|
|
|
|
My design of stuff is another issue.
Basic question here is
- is this a standard practice?
- Are there any issues?
|
|
|
|
|
It mostly depend if you are interested in generic programming and in having value vs pointer semantics.
until &*&x == &x whatever x, than what you did is true.
Of course if x overloads * and/or &, things may be not be as expected, but sometime this is wanted by certain generic algorithms.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
vikrams wrote: int* ptr = new int();
int& tmp = *ptr;
delete &tmp;
Another hint for not to be in trouble - if you delete by using reference, then the ptr variable will become a dangling pointer.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
M making a search application in that m using SHBrowseForFolder, while running the application, when we click on the BRowse button second time then i want the previous folder(which we selected when we pressed first time) should come as selected. But now Mycomputer is coming selected everytime i click the Browse button.
Please someone tell me how to do.
This is my current code
void CTestingDlg::OnBrowse() { BROWSEINFO bi; TCHAR szDir[MAX_PATH]; LPITEMIDLIST pidl;
|
|
|
|
|
Hi,
I am not sure there may be some standard method, but you can save the previously opened folder path in an INI file.
When open dialog next time, initialize BROWSEINFO->pidlRoot to the previously opened folder path from INI file.
Hope you got some idea..
Thanks,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
Most applications use registry to get the last file that was opened. You can then use a parameter in BrowseInfo to open the previously selected folder.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi all,
Now I m using VC++ 2005,i want to use keyboard fast asseccing on Button control, how can i do this?
When i m using the VC++ 2006 then there i m using & with the caption of button and the access of that button with the help of assigning buttons.
But it is not working in VC++ 2005.
Please help me for this.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|
Expecting good explanation
|
|
|
|
|
|
The size of object of a class that contains int variable is 4bytes then why the size of class 1byte is not considered along with 4bytes?.
|
|
|
|
|
I don't quite understand what you are asking? But I will make a guess. You are saying that a class containing since int will have objects of size 4 bytes. Then why does empty class takes 1 byte instead of 4 bytes? Because 1 byte is enough for the purpose of differentiating two objects of an empty class. So why use 4 bytes and waste 3 bytes per object?
-Saurabh
|
|
|
|
|
My previous question is not so clear, let me clear my doubt here
class A
{
};
class B
{
int k;
};
int main()
{
A a;
int i = sizeof(a); -----> the value of i is 1byte
B b;
int j = sizeof(b); -----> the value of j is 4bytes
return 0;
}
why the value of j is 4bytes why not 5 bytes[size of int variable(4bytes) + size of class(1byte))
|
|
|
|
|
class objects have to have non zero memory size.
In case of class A it is empty since compiler cant determinne the size it will allocate minimum allocation unit i.e. 1 byte for its object.
In case of class B it has int variable so compiler knows its size and hence will allocate appropriate size i.e 4 bytes for int for its object.
Regards,
Sandip.
|
|
|
|
|
Because class B now has data, and doesn't need to insert a byte to maintain memory integrity.
|
|
|
|
|
|
Kwanalouie wrote: The problem I have is that when the cursor is at the top of the client window and I click the right mouse button, the value of point.y is around 72 instead of zero. When I use this same code in the OnLeftMouseDown routine, the value of point.y at the top of the Client window is zero.
Because OnContextMenu point parameter is in screen co-ordinates and your right click handler point is in client co-ordinates so call ClientToScreen/MapWindowPoints to convert to screen co-ordinates. That's why it's zero in right click handler and 72 in context menu handler.
From MSDN for OnContextMenu point parameter
Position of the cursor, in screen coordinates, at the time of the mouse click.
From MSDN for OnLButtonDown point parameter
Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Thursday, June 5, 2008 11:52 PM
|
|
|
|
|
Thanks a lot. That did the trick!
|
|
|
|
|
Which one and can it be done taking VS 6.0 C++ code and bringing it into one of the new VS 2xxx versions? We would like not to recode at this time and just import/rebuild under the newer environments.
Any problems with doing this?
thanks
|
|
|
|
|
Kyle P wrote: ...can it be done taking VS 6.0 C++ code and bringing it into one of the new VS 2xxx versions?
Yes.
Kyle P wrote: We would like not to recode at this time and just import/rebuild under the newer environments.
Highly unlikely. Unless you already had some real clean (i.e., compliant) C++ code, there'll be code changes.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Is there a guide of what to look at first and common things to change? Any documentation form MS on this or other guides?
thanks again
|
|
|
|
|
The most important issues deals with template and partial specialization.
Pay special attention to the use of the typename keyword, and to the way parameter lists are declared while reusing template declarations, since some scope rule are different.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
I suspect what you'll likely run into will be Unicode and deprecation issues.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi, I'm using C++ with MFC and VC++ 2005.
My problem is this:
I have two different projects, one dependent on the other. The first project compiles to produce a static lib. It also includes a namespace, let's call it "NAM" for the purpose of this question. The second project then includes the headers from the first project, and the static lib in its settings.
This all seems fine, and the first project (the lib) compiles with no problems. However when I compile the second project, I receive linker errors for all of the namespace functions called in the first project's single .cpp file. So for instance, in project 1, I might have the function:
NAM::Find_String(void)
Which compiles just fine when I compile that project alone. But in the second project, I get this weird linker error that says:
error LNK2001: unresolved external symbol _Find_String
What am I doing wrong? It's like somehow the second project doesn't see the 'namespace' declared in the first project even though all the headers (there are only 3) are included and the lib is linked correctly.
KR
|
|
|
|