Global Method 
Author Message
 Global Method

hello group

 I want a global Method inside atl com, which should b visible inside my all
.cpp n .h  files . where should i declare and implement that.

thanx in advance.



Fri, 11 Feb 2005 22:07:59 GMT  
 Global Method
This is contradiction of terms. Method means belongs to a class,
global means belongs to the global namespace. These two are
mutually exclusive. If you simply mean a global function, well
any header you include in the header where your class is declared
will do...

At any rate, C++ language discussions should go here:

microsoft.public.vc.langauge

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> hello group

>  I want a global Method inside atl com, which should b visible inside my all
> .cpp n .h  files . where should i declare and implement that.

> thanx in advance.



Sat, 12 Feb 2005 02:35:32 GMT  
 Global Method
hello  Group

I have header file "GlobalFile.h" in this a method ValidateMethod() .
i have two classes Jobs and Companys inside my atl com , in each class i
have  a method add() .Inside  this Add method i'm calling ValidateMethod() .
IF i include "GlobalFile.h" either  in Jobs.cpp or in Companys.cpp file and
call Add method it works fine . But if I include
"GlobalFile.h" inside both the .cpp's . it gives me linking error of this
type

Jobs.obj : warning LNK2005: "short __cdecl ValidateMethod()"
(?ValidateMethod() already defined in Companys
.obj; second definition ignored

my code is like this

#ifndef _GLOBALFILE_H
#define _GLOBALFILE_H

ValidateMethod()
{
   MessageBox(0 , "hello world" , "test" , 0);

Quote:
}

#endif

if i use  /FORCE   (Force File Output)
it overrides n works . Is there any other solution.

10x in advance.



Sat, 12 Feb 2005 21:00:51 GMT  
 Global Method
hello  Group

I have header file "GlobalFile.h" in this a method ValidateMethod() .
i have two classes Jobs and Companys inside my atl com , in each class i
have  a method add() .Inside  this Add method i'm calling ValidateMethod() .
IF i include "GlobalFile.h" either  in Jobs.cpp or in Companys.cpp file and
call Add method it works fine . But if I include
"GlobalFile.h" inside both the .cpp's . it gives me linking error of this
type

Jobs.obj : warning LNK2005: "short __cdecl ValidateMethod()"
(?ValidateMethod() already defined in Companys
.obj; second definition ignored

my code is like this

#ifndef _GLOBALFILE_H
#define _GLOBALFILE_H

ValidateMethod()
{
   MessageBox(0 , "hello world" , "test" , 0);

Quote:
}

#endif

if i use  /FORCE   (Force File Output)
it overrides n works . Is there any other solution.

10x in advance.



Sat, 12 Feb 2005 21:27:36 GMT  
 Global Method

Quote:
> hello  Group

> I have header file "GlobalFile.h" in this a method ValidateMethod() .
> i have two classes Jobs and Companys inside my atl com , in each class i
> have  a method add() .Inside  this Add method i'm calling ValidateMethod()
.
> IF i include "GlobalFile.h" either  in Jobs.cpp or in Companys.cpp file
and
> call Add method it works fine . But if I include
> "GlobalFile.h" inside both the .cpp's . it gives me linking error of this
> type

> Jobs.obj : warning LNK2005: "short __cdecl ValidateMethod()"
> (?ValidateMethod() already defined in Companys
> .obj; second definition ignored

> my code is like this

> #ifndef _GLOBALFILE_H
> #define _GLOBALFILE_H

> ValidateMethod()
> {
>    MessageBox(0 , "hello world" , "test" , 0);
> }

> #endif

Don't define global functions in header files (unless they are inline or
templates). Only put a declaration into the heder file, like

    void ValidateMethod();

and put the implementation into a separate CPP file.

    Heinz



Sat, 12 Feb 2005 22:25:51 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. "Global" methods in MC++

2. Global variable or not global variable

3. CONFLICT - Global Var of a .LIB Vs Global Var of a program which uses the LIB

4. Uninitialized global data (was Re: Global variables)

5. To be Global or not to be Global??

6. Tunnelling service methods into a single method

7. Can a method be declared inside another method?

8. Why static method cannot be abstract method?

9. Dynamic Method call ( Invoke method ) failing in service when compiled as ReleaseMinDependancy

10. calling an interface method from another method in the same class

11. Calling a method from within a method, legal?

 

 
Powered by phpBB® Forum Software