|
In general, I think everyone will agree that header files should be used for declarations, and source files for definitions. Actually, sometimes you won't be able to do without source files. For example for static variables, for initialization of global variables, etc etc
|
|
|
|
|
doneirik wrote:
To avoid having to much files...
why would you like to reduce the number of files ? to have only one that is about 80Kb weight ???
wow, good luck ! lol
well, in my case, i prefer having several file (one header associated with a module - .cpp), where each module implements a logical section.
Well, you should not be so strict either. For example, if you have a set of functions that are about to represent some Exceptions of your own in your program, you can put them in the same file, including also the functions implementation if they are writing on few lines.
Of course, this is a suggestion, you can do whatever you like, but i also think that if most of experienced programmers separate the actual instructions from declarations, they do have some reasons...
doneirik wrote:
Do the compiler treat code in the .h file differenly?
actually, .h files are not compiled. The #include directive tells the pre-processor to copy the content of the .h file where such instruction is written in a file.
doneirik wrote:
Is there code that cannot be written in the header file?
Yep, affirmative !!
A header can contain :
- named namespaces (namespace N { /*...*/ } );
- Types definitions (struct Point { int x, y; }; )
- Templates declarations (template<class T> class Z; )
- Templates definitions (template<class T> class V { /*...*/ }; )
- Functions declarations (extern int strlen(const char*); )
- inline functions definitions (inline char get(char* p) { return *p++; } )
- Datas declarations (extern int a; )
- Constants definitions (const float pi = 3.141593; )
- Enumerations (enum Light { red, yellow, green }; )
- Names declarations (class Matrix )
- Inclusion directives (#include <algorithm> )
- Macros definitions (#define VERSION 12 )
- Conditional compilation directives (#ifdef _cplusplus )
- Comments (/* End of file */ )
In the other hand, a header might never contain :
- Ordinary functions definitions (char get(char* p) { return *p++; } )
- Datas definitions (int a )
- Arrays definitions (short tbl[] = {1, 2, 3}; )
- Non-named namespaces (namespace { /*...*/ } )
- Exported templates definitions (export template<class T> f(T t) { /*...*/ } )
Moreover, Mr Stroustrup tells us in it famous book "The C++ Language" the following advices :
- Use headers to represent interfaces and to emphasize the logical structure;
- A header file must be included in a source file that implements its functions;
- Do not define global entities with the same name but not the same meaning within different units of translation (.cpp source files);
- Avoid writing non-inline function definitions inside headers;
- Use #include directive only in global scope and in namespaces;
- Never include incomplete declarations;
- Use made safe inclusions;
- Include C headers inside namespaces to avoid global names;
- Headers should be autonomous
- You may distinguish user interfaces from implementation functions interfaces;
- You may distinguish average users' interfaces from expert users' interfaces;
- Avoid non-local objects that need to be initialised with the execution, when the code have to be included in a program written in another language.
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Just reorg your directories and put arrange the files that way. The only implementation I put in header files is 1-line returns and/or single "set" functions.
At least I'm not as bad as some people I know, they have a seperate cpp file for every function in the header! My rule is, break out another cpp if your function is 30-ish lines or longer, just for clarity. (although there should be very few cases where you need such a big function)
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
hii...
how do i use CreateDialogIndirect to create a dialog box?
how can the DLGTEMPLATEEX be used to retrieve /specify the properties of an existing dialog box?
and how is the callback function DialogProc to b used?
regards,
kedar.
|
|
|
|
|
|
it is a program of MSDN , which i have written in console win32 application because in win32 applicaiton it was also giving problems.It gives an error that SetDICreateDeviceInfoList() does not take 7 parameters....Plz help me out
#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
DWORD Err;
HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid)
/*
Routine Description:
Retrieves the device information set that contains that contains
the devices of the specified class.
Parameters:
InterfaceClassGuid - The interface class GUID.
Return Value:
If the function succeeds, the return value is a handle to the
device information set.
If the function fails, the return value is zero.
*/
{
HDEVINFO DeviceInfoSet;
HDEVINFO NewDeviceInfoSet;
// Create a device information set that will be the container for
// the device interfaces.
DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
if(DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err );
return 0;
}
// Retrieve the device information set for the interface class.
NewDeviceInfoSet=SetupDiGetClassDevsEx( InterfaceClassGuid,NULL,NULL,DIGCF_PRESENT | DIGCF_DEVICEINTERFACE,DeviceInfoSet,NULL,NULL);
if(NewDeviceInfoSet == INVALID_HANDLE_VALUE)
{
Err = GetLastError();
printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err );
return 0;
}
return NewDeviceInfoSet;
}
int main(int argc, TCHAR* argv[])
{
DoDeviceEnum(NULL);
return 0;
}
|
|
|
|
|
i have included windows.h, stdio.h, setupapi.h
|
|
|
|
|
brilliant101 wrote:
It gives an error that SetDICreateDeviceInfoList() does not take 7 parameters....
Right, it only takes two, which is what you have. SetupDiGetClassDevsEx() does take seven parameters, however, which you also have. Please provide the error verbatim from the compiler.
Unless you are just looking for something extra to do, there is no reason to respond to all of your posts with the name of the header files that have been included. Using < and > correctly will suffice.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
How to get text on screen at current mouse position.
le van giang
|
|
|
|
|
I can see that you're cross posting, so what language are you interested in?
Furthermore, your question is a bit fluffy, I think you have to be a bit more specific.
As leppie says in the C# forum, it's not possible to just get the text at a certain point.
But you can get the text from the HWND at the current corsor position, look up these functions in the Win32 API: WindowFromPoint, SetWindowsHookEx, GetWindowText, ChildWindowFromPoint.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
do you want the text to appear within your application window or anywhere in screen(including the area out of your application window).
1) if you want the text to appear within your application window,
handle WM_LBUTTONDOWN OR onLButtonDown(in mfc), and within that get the device context of client(GetClientDC(this)) and display the text using TextOut or DrawText.(use point for mouse location)
2) if you want the text to appear anywhere in screen,
-Capture the mouse using SetCapture.
-Get the screen device context, using CreateDC(NULL).
-display the text using TextOut or DrawText.(use point for mouse location)
|
|
|
|
|
The word "get" is ambiguous here. Do you want to read text from the screen, or write text to the screen?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want to read text from anywhere on screen.
|
|
|
|
|
That will require use of the IAccessible interface, specifically the get_accValue() method.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello,
Could anyone tell me how to cope with this error message.
the start of my code goes like
#pragma once<br />
<br />
using namespace std;
...
I get the errormessage that the namespace does not exist, and msdn provide little information about this error message.
error C2871: ´std´:a namespace with this name does not exist
Sorry if I provide to little code or further descriptions...
But maybe somebody has a tips
best regards
doneirik
|
|
|
|
|
That should compile OK on any machine. Exactly on what line did you get the error message? Maybe where the error is generated your code is at a different scope not within that of your "using" declaration? Maybe where the error is generated the header file with your "using" declaration is not included?
|
|
|
|
|
this can come from the files you really include.
for example :
#include <string.h> this will include all the C standard function to manipulate C-string (strcat(), strlen(), etc...) in the global namespace : ::strcat(), ::strlen(),...
#include <CSTRING> this will put the functions in the std namespace : std::strcat(), std::strlen(), ...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
doneirik wrote:
Could anyone tell me how to cope with this error message.
the start of my code goes like
#pragma once
using namespace std;
...
I get the errormessage that the namespace does not exist, and msdn provide little information about this error message.
error C2871: ´std´:a namespace with this name does not exist
You probably should include a file with code in namespace std before 'using' namespace std, e.g.
#include <vector>
using namespace std;
|
|
|
|
|
hai ..
can anybody help me in my problem?My problem is to maintain constant size to one text file.eg 500kb then if i add any thing it will not show that text files size increasing.please help me.
regards
shaanu
shan
|
|
|
|
|
How about (temporarily) using a copy of the text file instead and add to that?
|
|
|
|
|
I am storing 32 bit keys.so i want to store some more keys.but the size of text file should be constat.i want to limit its size by some 500 kb like that.so what should i do for make constant size of text file in vc++?
shan
|
|
|
|
|
what about overwriting the file content ???
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
If you add to a file, it's going to increase in size. There is no way around this. This is a very odd requirement.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hi all,
I want to draw 3D object like a ball using GDI+ Graphics,Brushes..Can any body Guide me to do it?
Thanks in advance..
|
|
|
|
|
dear sir.
i am an MSc studient, I need some informations about my project which its titled "image compression using multiwavelet transform" (source code program to do it)in visual C++
with my regards
|
|
|
|