By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,391 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,391 IT Pros & Developers. It's quick & easy.

where to declare and where to define the function?

P: 56
There are two different directories.

sparse/src/stk/dmg_apiutil
and
sparse/src/stk/dmg_meta_doc

Inside these two directories there are lot of C++ files.

I have written a function:

void cFreeMemory( char* entityName, void* ptrStruct )
{
// Check if the Pointers are NULL
if( ptrStruct != NULL && sGetEntityByName( entityName ) != NULL )
{
sEntityFree( sGetEntityByName( entityName ),
( void** )&ptrStruct,
sYES );
}
}

How I could access this function inside every file in the two directories? I mean where and how I need to declare this function so that I can access from every file inside the mentioned two directories.

Thanks in advance.
Aug 22 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 10K+
P: 11,448
There are two different directories.

sparse/src/stk/dmg_apiutil
and
sparse/src/stk/dmg_meta_doc

Inside these two directories there are lot of C++ files.

I have written a function:

void cFreeMemory( char* entityName, void* ptrStruct )
{
// Check if the Pointers are NULL
if( ptrStruct != NULL && sGetEntityByName( entityName ) != NULL )
{
sEntityFree( sGetEntityByName( entityName ),
( void** )&ptrStruct,
sYES );
}
}

How I could access this function inside every file in the two directories? I mean where and how I need to declare this function so that I can access from every file inside the mentioned two directories.

Thanks in advance.
Declare that function in a .h file and include that file in every .cpp file that needs
that function. Define that function somewhere in a .cpp file; possibly its own
.cpp file or an already existing one. Compile and link everything and voila.

kind regards,

Jos
Aug 22 '07 #2

P: 56
Should I need to declare that as static ?
Aug 22 '07 #3

Expert 10K+
P: 11,448
Should I need to declare that as static ?
If you want to use that function in other translation units (other .cpp file) you
most certainly shouldn't declare (and define) that function as static. It needs
external linkage, because other functions in other translation units need to
be able to find it. Static functions can only be used in the translation unit
where they are defined themselves.

kind regards,

Jos
Aug 22 '07 #4

P: 56
Thanks. Thanks a lot.
Aug 22 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.