Initializing a static object 
Author Message
 Initializing a static object

Add

    MUTEX  ATOMIC::Mutex = NULL;

    to the implementation ( .cpp ) file.

--
Cheers
Check Abdoul
----------------


Quote:
> Hi,
> If I have something like:

> class ATOMIC {
>  .
>  .
>  .
> private:
>   static MUTEX Mutex;
> }

> How do I intialize user defined static members.
> MUTEX has a constructor MUTEX(void). I am getting a link
> error:

> atomic.obj : error LNK2001: unresolved external
> symbol "private: static class MUTEX  ATOMIC::Mtx"

> Thanks,

> Vikas



Sun, 20 Feb 2005 05:06:46 GMT  
 Initializing a static object
Hi,
If I have something like:

class ATOMIC {
 .
 .
 .
private:
  static MUTEX Mutex;

Quote:
}

How do I intialize user defined static members.
MUTEX has a constructor MUTEX(void). I am getting a link
error:

atomic.obj : error LNK2001: unresolved external
symbol "private: static class MUTEX  ATOMIC::Mtx"

Thanks,

Vikas



Sun, 20 Feb 2005 04:51:47 GMT  
 Initializing a static object
C++ standard support code like this:

class ATOMIC{
...
private:
 static MUTEX Mutex=NULL:

Quote:
};

I don't know about  VC 7, but VC++ 6.0 doesn't support this feature.
So, you have to add

MUTEX ATOMIC::Mutex=NULL;

into your cpp file.


Quote:
> Hi,
> If I have something like:

> class ATOMIC {
>  .
>  .
>  .
> private:
>   static MUTEX Mutex;
> }

> How do I intialize user defined static members.
> MUTEX has a constructor MUTEX(void). I am getting a link
> error:

> atomic.obj : error LNK2001: unresolved external
> symbol "private: static class MUTEX  ATOMIC::Mtx"

> Thanks,

> Vikas



Sun, 20 Feb 2005 14:48:17 GMT  
 Initializing a static object
C++ standard 9.2/4: A member-declarator can contain a
constant-initializer only if it declares a static member (9.4) of
integral or enumeration type. The OP says MUTEX is a class with a
constructor, so it cannot be an integral or enumeration type.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> C++ standard support code like this:

> class ATOMIC{
> ...
> private:
>  static MUTEX Mutex=NULL:
> };

> I don't know about  VC 7, but VC++ 6.0 doesn't support this feature.
> So, you have to add

> MUTEX ATOMIC::Mutex=NULL;

> into your cpp file.



> > Hi,
> > If I have something like:

> > class ATOMIC {
> >  .
> >  .
> >  .
> > private:
> >   static MUTEX Mutex;
> > }

> > How do I intialize user defined static members.
> > MUTEX has a constructor MUTEX(void). I am getting a link
> > error:

> > atomic.obj : error LNK2001: unresolved external
> > symbol "private: static class MUTEX  ATOMIC::Mtx"

> > Thanks,

> > Vikas



Sun, 20 Feb 2005 23:29:07 GMT  
 Initializing a static object

Quote:

> C++ standard support code like this:

> class ATOMIC{
> ...
> private:
>  static MUTEX Mutex=NULL:
> };

Considering the information given by the original poster
on MUTEX having a constructor I would say that the
C++ standard does not tolerate such code.

Quote:
> I don't know about  VC 7, but VC++ 6.0 doesn't support this feature.
> So, you have to add

> MUTEX ATOMIC::Mutex=NULL;

The original poster has not given any information
on MUTEX having that kind of a constructor. Having
only the default one I would insert

MUTEX ATOMIC::Mutex;

Quote:
> into your cpp file.

Sergei
Quote:
> into your cpp file.



> > Hi,
> > If I have something like:

> > class ATOMIC {
> >  .
> >  .
> >  .
> > private:
> >   static MUTEX Mutex;
> > }

> > How do I intialize user defined static members.
> > MUTEX has a constructor MUTEX(void). I am getting a link
> > error:

> > atomic.obj : error LNK2001: unresolved external
> > symbol "private: static class MUTEX  ATOMIC::Mtx"

> > Thanks,

> > Vikas



Sun, 20 Feb 2005 23:57:39 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Initialize static object

2. GP Fault Initializing static array of objects

3. initializing static object

4. vc wouldn't initialize static members in static libraries

5. Static array containing non static objects and functions

6. Static Library static object initialization

7. How to initialize a static array ?

8. Initializing static arrays

9. Initialized vs. unitialized data and static

10. How do I initialize a const (static) array?

11. initializing global/static

12. Initializing Static Variables

 

 
Powered by phpBB® Forum Software