|
Iain Clarke wrote: I hope the light at the end of the tunnel isn't a train.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Thanks Iain,
My question is, why a non-const reference can not binded to a rvalue?
I think the reason is rvalue is not addressable? And we can not change the rvalue through its reference? Are there any other reasons? I am not quite sure whether my understanding is fully correct. Since there are some
non-modifiable lvalues (so we do not always need to modify values
through its reference). I am still studying what is the reason in
essence in compiler why a non-const reference can not be binded to a
rvalue.
Please feel free to correct me if I am wrong.
have a good weekend,
George
|
|
|
|
|
I know what they're on about now, having read the page you point to.
In short, for those (like me) who don;t want to slog through too much work to help someone...
class A
{
...
};
class B
{
public:
B ( A &a );
B ( const A &a);
....
};
...is the example MS use.
As it a warning, and one you have to explicitly enable. So microsoft are labelling using a non-const reference as inadvisable, not a failure.
This non-const reference rule applies to more than constructors. Imagine operator= members, which can be mutated into copy constructors.
void MyFunction (CBigClass &big)
{
COtherClass other;
other = big;
other.DoStuff ();
}
So far so good? big is a big class, involving connecting to databases on construction, etc. You don't want to make new ones, so you pass it by reference or reference. But you don't want the bugs that come by passing by pointer. What if some evil person passed me a NULL? So you pass by reference.
The above function looks pretty innocuous? You would think nothing of using...
CBigClass b;
b.Blah ();
MyFunction (b);
Now imagine...
class COtherClass
{
....
COtherClass &operator=(CBigClass &b);
....
};
COtherClass &COtherClass::operator=(CBigClass b)
{
....
b.DoSomethingNotConst ();
....
return *this;
}
Suddenly, you have a bug that doesn't manifest until much later, and would be really hard to track down. After all, you're just using =! Where's the harm in that?
And if you say
"But Iain! I'm the mighty George! So mighty, I was called George twice! I would never use a bad member function of a class I'm supposed to just be copying! Nevermind my addiction to exclamation points!!!", then I would say...
"In that case, what's the harm in declaring the = function as
COtherClass &operator=(CBigClass const &b);
after all, you weren't going to anything non-const, were you?"
Most of the time, when things have to be one way, just ask yourself, what if they didn't? You can usually find something bad that would happen.
Here endeth the lesson, from the gospel according to Iain. My fingers are now tired.
Iain.
|
|
|
|
|
Thanks Iain,
Is there a typo in your code?
The declaration of assignment operator is (input parameter is reference type),
COtherClass &operator=(CBigClass &b);
But the implementation is (input parameter is object type, not reference type)
COtherClass &COtherClass::operator=(CBigClass b)
regards,
George
|
|
|
|
|
|
Hi Iain,
This is what you mentioned in your long post,
Iain Clarke wrote: Suddenly, you have a bug that doesn't manifest until much later, and would be really hard to track down.
I have re-read your code, but I can not see any bugs. It is appreciated if you could point out.
If you mean the input parameter should be defined as non-const reference, I do not think it is a bug, it is a design and function limitation.
regards,
George
|
|
|
|
|
The bug is the DoSomethingNotConst () being called in the operator = function, and the compiler not telling you off, because you hadn't consted the reference(s) in the operator= function.
In the following snippet
Class C a,b;
b.FillWithValues ();
a = b;
you would expect a = b to not change b at all.
And if you write the copy constructor using a const reference, then it is harder to mess up and make that mistake. That's all. The const keyword just makes it that bit harder for you to mess up.
If you're a super programmer who never makes mistakes, and remembers the reason for every line of code you've ever written, then you never need the const keyword at all.
Guess what. You're not that super programmer. Neither am I.
const is like a sports cup. It makes it that bit harder to have a nasty injury.
Iain.
|
|
|
|
|
Thanks Iain,
My question is answered. You are a super developer whose thoughts are not easily caught.
regards,
George
|
|
|
|
|
I downloaded a slip code from http://support.microsoft.com/kb/308669[^].And build a console project and insert the source files in VS2005.
But there are such errors occured like bellow:
1>main2.obj : error LNK2019: unresolved external symbol @_RTC_CheckStackVars@8 referenced in function "void __cdecl DebugPrint(unsigned short,char *,...)" (?DebugPrint@@YAXGPADZZ)
1>main2.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function "void __cdecl DebugPrint(unsigned short,char *,...)" (?DebugPrint@@YAXGPADZZ)
1>main2.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
1>main2.obj : error LNK2001: unresolved external symbol __RTC_InitBase
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiDestroyDeviceInfoList@4 referenced in function _main
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiGetClassDevsA@16 referenced in function _main
1>main2.obj : error LNK2019: unresolved external symbol __imp__CM_Reenumerate_DevNode@8 referenced in function "int __cdecl GetRegistryProperty(void *,unsigned long)" (?GetRegistryProperty@@YAHPAXK@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiGetDeviceRegistryPropertyA@28 referenced in function "int __cdecl GetRegistryProperty(void *,unsigned long)" (?GetRegistryProperty@@YAHPAXK@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__CM_Get_Device_IDA@16 referenced in function "int __cdecl GetRegistryProperty(void *,unsigned long)" (?GetRegistryProperty@@YAHPAXK@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiEnumDeviceInfo@12 referenced in function "int __cdecl GetRegistryProperty(void *,unsigned long)" (?GetRegistryProperty@@YAHPAXK@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiGetDeviceInterfaceDetailA@24 referenced in function "void __cdecl GetInquiryData(char const *)" (?GetInquiryData@@YAXPBD@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__SetupDiEnumDeviceInterfaces@20 referenced in function "void __cdecl GetInquiryData(char const *)" (?GetInquiryData@@YAXPBD@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__CM_Get_Sibling@12 referenced in function "void __cdecl GetChildDevices(unsigned long)" (?GetChildDevices@@YAXK@Z)
1>main2.obj : error LNK2019: unresolved external symbol __imp__CM_Get_Child@12 referenced in function "void __cdecl GetChildDevices(unsigned long)" (?GetChildDevices@@YAXK@Z)
And I also include <stdarg.h>,<rtcapi.h> in the code.
Someone would like to tell me,how to resolve such errors?
Thanks.
GOOD LUCK
|
|
|
|
|
All linker errors. Are you missing an import library or two in your
project settings?
setupapi.lib should take care of the SetupDi___ externals. I'm not sure
about the top four
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply.
I search the four errors every where,but the questions seems to laying every where,but no answer!
I only want to get a usb device's SCSI data,so I have to use IOCTL_SCSI_GET_INQUIRY_DATA to send a query request to the device's driver.In a word,the device's firmware datas I want to retrieve.
The code was download from microsoft!
Thank you once again.
Best wishes.
|
|
|
|
|
There wasn't a project or makefile with the code?
I wonder if it's part of the device driver sdk (DDK)...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I also agree with you.
My PC has DDK installed,too.
I think the problem is that,all of us don't know what lib files should import.
I hope,the problem would be resolved.
Best regards.
|
|
|
|
|
add Mark Salsbery Comment
All linker errors. Are you missing an import library or two in your
project settings?
you need add hid.lib setupapi.lib in menu Project\project settings slect L ink and add
hid.lib setupapi.lib in to Object. Libary modules
i have same Problem as you ,and i resolved it
|
|
|
|
|
Hi Friends,
Could any one tell me, How to count number of files in a folder.
Ex:
C:\My Documents\New Folder
I need to count all the files in this path.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
you can use _findfirst() and _findnext().
The second function use the return value of the first function to retrieve.
You can see more details in MSDN.
But you should pay attention to the two found results,whose name is "." and "..",they are the current folder and its parent folder!
You can test in MS-DOS.
|
|
|
|
|
Thank you friend,
This _findfirst() and _findnext() helped me solve this problem.
Thanks a lot once again.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
If you are using DlgDirList you can get count of files.
|
|
|
|
|
Hi all,
Actually the searching criteria is changed in codeproject, and i am unable to find the new one...Can anybody please tell me how to search a article for example(progress bar in mfc)
Thanks in advance
|
|
|
|
|
Now you have to use an expression to find out like this
AND, NOT, OR and grouping parentheses supported. Enclose phrases in quotes.
eg. CListCtrl; "Grid Control" ; ((C# AND NOT Grid) OR Spreadsheet)
Try this link it gives you info about progress bars
http://www.codeproject.com/KB/tree/progresshourglassfx.aspx[^]
Regards,
Pankaj Sachdeva
There is no future lies in any job but future lies in the person who holds the job
|
|
|
|
|
yes, even i experienced the same for a while. But I am getting pretty much used to it now.
If you want to see any articles in MFC, then you can find them on the left of the screen. its under the heading 'CHAPTERS'. under that, you go to 'platforms, frameworks & Libraries' and choose 'MFC'. You can also find the articles regarding MFC controls under the section 'Desktop Development'.
Or else, you can always use Google to find the articles here on CP. When I don't find the article that i am looking for with the search option here in CP, I use Google to search for the article. I put the key words in Google and Google gives me a direct link to the article. For example, to find the 'progress bar in MFC', i put the key words 'progress bar + MFC + codeproject' in Google and I get a direct link to articles explaining about progress bar in mfc on codeproject. you can easily navigate from there to find similar articles. Its a strange approach, but it works for me.
Regards,
Vijay.
|
|
|
|
|
Hi all,
I have two applications, console application with MFC support and MFC DLL application. I want to connect both those two application together. Console application gives the required data to DLL.
So how should I do it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hello again everyone
Before that i would like to tell u all that im really new and dumb to .NET. Hope you guys can help me. I tried to search the solution to my problem but still couldnt find anything.
What im trying to do is to create a really simple internet connection detection which is running under a win32 console. The program will detect if there is any connection to the internet, if yes then it will print yes. If no connection then it will print out no connection using printf() statement.
I know that the InternetGetConnectedState API can help me. but still im not so sure on how to use it. Really dumb me...the scenario is like this
I already link the VC++ project to the Wininet.lib since it required that lib and a header file called Wininet.h (as refered in MSDN). I try to code just by adding the header file to the source code
<br />
#include "stdio.h"<br />
#include "Wininet.h"<br />
void main()<br />
{<br />
}<br />
using the code above, compile, it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file. The first error was "error C2061: syntax error:Identifier 'HINTERNET'. The question is, am i missing something. Does VC++ supports this API? I've search the internet (forums..etc) and all of them were implemented using C# or VB. Is there any source code samples using this API which can be run only in a simple win32 console application? Thank you everyone. Really appreciate any help. Thanks again.
|
|
|
|
|
Kogee San wrote: it generates more than 100 error which particularly made the compiler to stop compiling due to error exceeds 100. all of the errors come from the Wininet.h header file.
modify ur code as follows
#include "stdio.h"
#include <windows.h>
#include "Wininet.h"
void main()
{
}
|
|
|
|
|
wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.
|
|
|
|