| | |
Some Code
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 290
Reputation:
Solved Threads: 7
Hi ,i just have a fhew code witc i do not understand clear.Can you make some explain.
It is category from C++ Win32 API.
// And i did not typed (sorry )
s.c_str() how it can be this ?
Thank you for your effort of reading.
It is category from C++ Win32 API.
C++ Syntax (Toggle Plain Text)
typedef std::basic_string<TCHAR> ustring; inline int ErrMsg(const ustring& ); What this mean ustring& ?
C++ Syntax (Toggle Plain Text)
ustring classname=_T("SIMPLEWND"); ErrMsg(_T("Failed to register wnd class");
// And i did not typed (sorry )
C++ Syntax (Toggle Plain Text)
inline int ErrMsg(const ustring& s) { return MessageBox(0,s.c_str(),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION); }
Thank you for your effort of reading.
Last edited by kv79; Jan 7th, 2008 at 10:03 am.
>s.c_str() how it can be this ?
c_str is a member function of the basic_string class. Perhaps it would make more sense to you if I said that the std::string class is actually a typedef:
c_str is a member function of the basic_string class. Perhaps it would make more sense to you if I said that the std::string class is actually a typedef:
C++ Syntax (Toggle Plain Text)
typedef std::basic_string<char> string;
I'm here to prove you wrong.
>Why he need bitwise operator on the end and know what mean on begin?
That's not the bitwise AND, it's the syntax for a reference type.
>So were is the difference between normal call?
There's no difference. The inline function might execute faster, or it might not. inline is really something you should forget about for now.
That's not the bitwise AND, it's the syntax for a reference type.
>So were is the difference between normal call?
There's no difference. The inline function might execute faster, or it might not. inline is really something you should forget about for now.
Last edited by Narue; Jan 7th, 2008 at 11:13 am.
I'm here to prove you wrong.
•
•
Join Date: Jan 2008
Posts: 3,829
Reputation:
Solved Threads: 501
The difference between
which is what you have, and
is that in the first function, the function is looking for a parameter that is "passed by reference". The second function is looking for a parameter that is "passed by value". The '&' character signifies "pass by reference" and basically stands for "address of".
C++ has pointers and addresses and the word "reference" and "dereference" come up often, as do the symbols '*', standing for "pointer to" and '&', meaning "address of".
The "ustring&" signifies "pass by reference". This means that any changes that the function makes to the parameter passed to it will also change the value of the original variable passed to it (they actually ARE the same variable I believe). Changing a "pass by value" parameter within the function will NOT change the original value passed to it. As for a link, googling "C++ pass by reference example" or "C++ pointer tutorial" gives quite a few good links. Here's an example I wrote up:
The result is that the variable changed after calling the "pass by reference" function. but not after calling the "pass by value" function. That function changed the value to "tiger" but went "out of scope" afterwards so the original animal stayed as "lion".
The result therefore is:
dog
lion
lion
rather than
dog
lion
tiger
I took out the "const" part of your function since I wasn't sure how it was being used or why.
C++ Syntax (Toggle Plain Text)
int ErrMsg(ustring& )
which is what you have, and
C++ Syntax (Toggle Plain Text)
int ErrMsg(ustring )
is that in the first function, the function is looking for a parameter that is "passed by reference". The second function is looking for a parameter that is "passed by value". The '&' character signifies "pass by reference" and basically stands for "address of".
C++ has pointers and addresses and the word "reference" and "dereference" come up often, as do the symbols '*', standing for "pointer to" and '&', meaning "address of".
The "ustring&" signifies "pass by reference". This means that any changes that the function makes to the parameter passed to it will also change the value of the original variable passed to it (they actually ARE the same variable I believe). Changing a "pass by value" parameter within the function will NOT change the original value passed to it. As for a link, googling "C++ pass by reference example" or "C++ pointer tutorial" gives quite a few good links. Here's an example I wrote up:
C++ Syntax (Toggle Plain Text)
#include <string> #include <iostream> using namespace std; void PassByReferenceFunction ( string& animalName); void PassByValueFunction (string animalName); int main () { string animal = "dog"; cout << "Animal is a " << animal << endl; PassByReferenceFunction (animal); cout << "Animal is a " << animal << endl; PassByValueFunction (animal); cout << "Animal is a " << animal << endl; system ("PAUSE"); return 0; } void PassByReferenceFunction (string& animalName) { animalName = "lion"; } void PassByValueFunction (string animalName) { animalName = "tiger"; }
The result is that the variable changed after calling the "pass by reference" function. but not after calling the "pass by value" function. That function changed the value to "tiger" but went "out of scope" afterwards so the original animal stayed as "lion".
The result therefore is:
dog
lion
lion
rather than
dog
lion
tiger
I took out the "const" part of your function since I wasn't sure how it was being used or why.
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the C++ Forum
- Previous Thread: help me plz
- Next Thread: OnCreate ()
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






