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.

typedef std::basic_string<TCHAR> ustring;
inline int ErrMsg(const ustring& );    What this mean ustring& ?
ustring classname=_T("SIMPLEWND");
ErrMsg(_T("Failed to register wnd class");

// And i did not typed (sorry )

inline int ErrMsg(const ustring& s)
{
return MessageBox(0,s.c_str(),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
}

s.c_str() how it can be this ?
Thank you for your effort of reading.

>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:

typedef std::basic_string<char> string;

Do you want to say that when i write
typedef std::basic_string<TCHAR> ustring;

i add a ustring to class basic_string who all ready exist with headers.
#include <tchar.h> or what?

>i add a ustring to class basic_string who all ready exist with headers.
No, you add an instantiation of basic_string that holds TCHARs and call it ustring. basic_string already exists in the <string> header.

Thank you very much.
And one more question.
Why author use
ustring& Why he need bitwise operator on the end and know what mean on begin?
Can you clear me inline?
I know that it is insert a copy of body of called function.
So were is the difference between normal call?

>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.

I got it ,
it is a constructor string( const string& s)

And he can't have a same name as a constructor
so he put a string&.
am i right?


omg but i have ustring&.

>am i right?
Uh, no. Read up on references.

Can you gave me some link, i spent hours to find what i want?

The difference between

int ErrMsg(ustring& )

which is what you have, and

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:

#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.

Thank you VernonDozier .
Thank you Narue.

You are a so nice guys .
You are making me happy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.