|
Thanks, Taka buddy!
If you have ever studied how the compiler is working,
you will see what is my trouble. Suppose functionA is defined
in a header file. The compiler will recognize functionA as
valid identifier in any translation unit that includes A.h.
The function has external linkage by default. So I think if
a function is not called by others, it will be a waste to
define the function in the header file. Define it in .cpp
file is just OK. Since compiler external linkage will make
my program larger. But I do not know whether I am correct.
Can anyone help?
regards,
George
|
|
|
|
|
Defining a function in a header simply tells the compiler that the function exists (somewhere else) and has the specified signature.
You need to do it so that the compiler won't flag an error when you try to use it. That's all. If you don't call that function, it won't make your EXE bigger.
Declaring it in a CPP file is *wrong* since it is easy to change the signature of the function and forget to update the other declarations. If you have it in a single place i.e. the header file, you are more likely to get it right. If you are using a C++ compiler, name-mangling means that the linker is likely to flag an error but it's still bad practice.
Software is everything. It also sucks. Charles Fishman [^]
Awasu 1.0.3 (beta)[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Thanks, Taka buddy!
Your reply has answered most of my questions. Now I
have a last question, can you show me a case
where the client code is not supposed to call that
function but we must define the function in .cpp file
and better not in .h file? I can not imagine that case.
regards,
George
|
|
|
|
|
Hello George,
Since MS introduced MC++ they've been promoting inline function definitions for classes. This renders the need for a separate header file a mere formality and thus some people actually avoid using header files.
But if you are planning on writing some global fucntions then it might be a darn good idea to keep them in a separate header file.
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Thanks, Nishant buddy!
When you say inline function. Do you mean define a
function inside the .h file?
What means "This renders the need for a separate header
file a mere formality and thus some people actually
avoid using header files" in your reply? Why people avoid
using that way? Can you show me an example?
regards,
George
|
|
|
|
|
George2 wrote:
When you say inline function
Something like :-
class Abc()
{
void Hello()
{
}
};
Hello is defined directly here as you can see. If you were using separate CPP and H files you'd have put just the declration in the H file and the definition would have been in the CPP file
George2 wrote:
Can you show me an example?
Well the main CPP file for an MC++ project need not have a H file. You juyst put all your classes into this main CPP file. And similarly any other classes might be fully defined in a H file (this time no separate CPP files)
Regards,
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Thanks, Nishant buddy!
George
|
|
|
|
|
Hi, everyone!
I have heard that type conversion operator will
produce ambiguity when the compiler is implicitly
converting your types for you when the error will
occur "there are two or more functions that match..."
But I have not found an example code. I just heard that
but have never met with the very case.
Can you show me one example of that?
regards,
George
|
|
|
|
|
Here's a really rough example
void f(int n) { }
void f(char* p) { }
class C
{
public:
operator int() { return 1; }
operator char*() { return "hi!"; }
};
main()
{
C obj;
f(obj);
}
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Thanks, Michael buddy!
George
|
|
|
|
|
Does there exist on sourceforge or similar a set of classes for an OOP interface and implementation for using FTP and P2P...?
I much prefer working with objects rather than c api's.
I would like them to be as platform independant as possible also, so MFC's classes won't cut it.
Thanks in advance.
BTW - I want open source (free would be prefered)
Cheers
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
My MFC7 app needs to be able to create a resource dll and add resources (string and html) to it on-the-fly. How would I go about doing that? I've looked around in MSDN and using Google, but I haven't found any information on doing that yet.
|
|
|
|
|
|
I agree with you, but unfortunately the programmers at Digital Anvil didn't think so when they made Freelancer Freelancer stores all the text information in a number of resource-only dlls, and I'm the maker of a mod manager program for Freelancer (FLMM). I'm wanting to let mods easily add new string/html resources to a dll for Freelancer to use.
I looked at that documentation, but it seems awfully complicated Do you know if there is any (free) code out there that would do what I want to do?
Thanks
|
|
|
|
|
I'd go the easier route - compile a bare-bones DLL and put that in your app, maybe stick it in as a binary resource. Then when you need to create a new DLL, use that bare-bones one as starting point and use the *UpdateResource() APIs to modify the resources (as long as you can require your users to have some flavor of NT).
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
That is EXACTLY what I was looking for; thanks!
I need to be able to work with Win98 and ME, though, so that might present a problem. I was looking at the MSDN documentation on UpdateResource(), and it said the following at the end:
"Windows 95/98/Me: UpdateResourceW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems."
Does that mean that the unicode version works with 98/ME?
|
|
|
|
|
IGx89 wrote:
Does that mean that the unicode version works with 98/ME?
It might, you'd just have to try it out (or search the net for someone else who's tried it and posted the results)
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
I use an older version of MSLU and it works just fine. The hardest part is getting it setup the first time. But once you get the linking process done properly, everything works great.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Copy empty resource dll and "UpdateResource" it.
It works!
Brian
|
|
|
|
|
I am new to this group so forgive me if I should have looked somewhere else...
In a modal dialog I have a checkbox and an edit fbox. If the checkbox is 'On', the edit field should be enabled. If the checkbox is 'Off', the edit box should be disabled. I have seen this technique in several applications.
Can anyone point me to some code that uses this technique. THe obvious search strings have not turned anything up for me.
Thanks
Tel Monks
|
|
|
|
|
You have to handle the "clicked" event for the checkbox, and then enable/disable the edit box accordingly:
m_Edit.EnableWindow( m_CheckBox.GetCheck() );
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
You can use the class wizard to automagically generate the message handler Miszuo mentioned above. In the class wizard, select the control, then in the window on the right, select WM_CLICK (i think that's what it is... )
This will map that message to an OnClickYourControl() function. That's where you put the aforementioned code.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Thanks to both.
The remaining problem is that I can't set the EnableWindow when the dialog comes up. That is to say that if the checkbox is not to be "on" (via a Message variable) the EditBox should come up disabled...
See what I mean?
Is there a hook that will allow me to disable the editbox if the checkbox is off?
Tel
|
|
|
|
|
You need to initialize the dialog in the OnInitDialog function, by handling the WM_INITDIALOG message. Add this handler with the class wizard that Nitron was talking about.
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
Perfect! That took care of the last thing.
Thanks to both of you, my spam detection program is in great shape. If anyone is interested in testing, write to tel@telgo.m
|
|
|
|