|
TheinstruTara wrote: That is why I am trying to make it global, so that I do not have to declare it again and again.
Why? What's wrong with a variable being declared when it is needed? You're not saving anything by using a global variable instead. That way of thinking has not been relevant with Windows in a number of years.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Well..I am not trying to save anything.
I have to type CString sql; everytime I have to use it. I guess just a bit lazy... And if there is a better way of doing it, then why not!
I do know that if a variable can be declared as totally global. Just wasn't sure how.
I guess, we all try to find easier way of doing things.Some toothbrush company has come out with, 'automated toothbrush' Batery operated stuff...
Fortitudine Vinsinues!
|
|
|
|
|
Automated Tooth brush is alreay there...But there is no available medicine for lazyness till now...
Look here.
http://www.pricegrabber.com/search_attrib.php/page_id=796/popup1%255B%255D=20:1765/
Pls dont ask for a stuff which have food for u
|
|
|
|
|
While you can use the extern solution provided, a better solution for you would be to define that string in your string table and declare a CString object to use it when needed.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
TheinstruTara wrote: then I have to declare it again as extern CString sqla in payroll.cpp (another dialog class)?
Keyword "extern" indicates that this variable has been declared elsewhere in the same module and tells the compiler to use that declaration.
TheinstruTara wrote: If you want to use CString sqla in all the functions of that particular .cpp file, you declare it in the header file.
That may be what you have been doing, but it's not right. You don't declare varaibles in a header, you only put macros, constants, type definitions (that sort of things) there.
In essense, header is about definition not declaration. People include your header because they want to use your type definitions, not the variables in your module!
Hope this is clearer.
Best,
Jun
|
|
|
|
|
But then, suppose I want to access a value (say some
double area = 3.14*m_Edit_r*m_Edit_r) )
calculated in one dialog box class's .cpp file from another dialog box or just another class then how is it done.
What I usually do is declare double area in Dialog1.h , do the calulation somewhere in Dialog1.cpp
Then, in Dialog2.cpp I access it this way pDlg->area + somethng ... where pDlg is a CDialog1 object;
So i have been doing it wrong?
Fortitudine Vinsinues!
|
|
|
|
|
TheinstruTara wrote: So i have been doing it wrong?
Aside from declaring the data member public, no, you did it right. Those variables should be private and be given accessor methods, though.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
As per classes, the header defines a class, which in truns encapsulates some data as members. You're not declaring data in the header directly; the header still only contains type definition, which is class in this case.
TheinstruTara wrote: Then, in Dialog2.cpp I access it this way pDlg->area + somethng ... where pDlg is a CDialog1 object;
So i have been doing it wrong?
No. This actually explains the class definition well. Your Dialog2 accesses "area" through the 1st Dialog object "pDlg", which is most likely declared as a member of Dialog2 in your header.
Best,
Jun
|
|
|
|
|
Thanks.
In conclusion, if I am making a module, I must not do it the same way as I do it for classes. But for simple class, I can declare variables in the header.
Fortitudine Vinsinues!
|
|
|
|
|
Jun Du wrote: In essense, header is about definition not declaration.
Header (.h) files contain declarations, while source (.cpp) files contain definitions. Declarations can be seen multiple times by the compiler, while definitions can only be seen once by the compiler. A definition is also a declaration, but a declaration is not also a definition.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Header (.h) files contain declarations, while source (.cpp) files contain definitions.
I have a feeling that the source file (.cpp) contains class implementation, not definition. The header contains the definition.
Best,
Jun
|
|
|
|
|
Jun Du wrote: I have a feeling that the source file (.cpp) contains class implementation, not definition. The header contains the definition.
For creating your own class, yes, but the scope of this thread was limited to using an existing object.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Thank you. That is what I was looking for.
Fortitudine Vinsinues!
|
|
|
|
|
I've looked and looked, but i can't seem to find any good articles on pointers....
its all so confusing to me....
I would appriecate if anyone could point (he he) me to a good article or something you read that you though was good on pointers and references..
It would help a lot thanks...
"C++ will solve any problem."
|
|
|
|
|
What level do you want the literature to be technically, beginner or more advanced?
Best,
Jun
|
|
|
|
|
If you could find both...both,
but beginner for starters would help....
"C++ will solve any problem."
|
|
|
|
|
Ok, a beginner's first: this CP article.
Search CP for "pointers" and you'll get tone of articles and code snippets.
Best,
Jun
|
|
|
|
|
|
Thanks!
"C++ will solve any problem."
|
|
|
|
|
You can also check out (and I recommend reading anyway), "The C++ Programming Language", "Effective C++", "Effective STL", and "Exceptional C++". While they all cover far more topics than just pointers, they will give you a good start to learning the language as a whole.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
#hackC++ wrote: I've looked and looked, but i can't seem to find any good articles on pointers....
http://c-faq.com/ptrs/index.html[^]
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is there a way to detect when a 3rd party application displays a messagebox?
|
|
|
|
|
Write a system wide hook for WH_CBT or something of your choice go through hooks .
Regards,
FarPointer
Blog:FARPOINTER
|
|
|
|
|
Probably not, as a message box is nothing but a dialog (#32770 class). Any application can have one of those displayed.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|