Getting a Linking error when using a static member variable in a DLL 
Author Message
 Getting a Linking error when using a static member variable in a DLL

Eg.

class __declspec( dllexport ) InfWindow
{
protected:
 static InfTexture*    m_pTexture;    // This can be changed allowing
different "styles".
public:

//--------------------------------------------------------------------------
-----
 InfWindow();
 virtual ~InfWindow();
public:
  INF_RESULT   SetStyle( InfTexture* pTexture );

Quote:
};

//--------------------------------------------------------------------------
---------
INF_RESULT InfWindow::SetStyle( InfTexture* pTexture )
{
 m_pTexture = pTexture;
 return INF_OK;

Quote:
}

This will give a linking error.

Does anyone know how to fix this?



Wed, 07 Jul 2004 21:27:02 GMT  
 Getting a Linking error when using a static member variable in a DLL

Quote:

>Eg.

>class __declspec( dllexport ) InfWindow
>{
>protected:
> static InfTexture*    m_pTexture;    // This can be changed allowing
>different "styles".
>public:

>//--------------------------------------------------------------------------
>-----
> InfWindow();
> virtual ~InfWindow();
>public:
>  INF_RESULT   SetStyle( InfTexture* pTexture );
>};

>//--------------------------------------------------------------------------
>---------
>INF_RESULT InfWindow::SetStyle( InfTexture* pTexture )
>{
> m_pTexture = pTexture;
> return INF_OK;
>}

>This will give a linking error.

>Does anyone know how to fix this?

You have to initialize all static data members:

InfTexture *InfWindow::m_pTexture = 0;

This should be done in the file space where you've outlined your
member function. You can't do that inside any member function.

HTH

Chad



Wed, 07 Jul 2004 23:16:33 GMT  
 Getting a Linking error when using a static member variable in a DLL
Thants great, Thanks.

However how also could I get it to be accesible from outside it's dll.

If I have the function

static InfTexture* InfWindow::GetTexture(){    return m_pTexture;    }

This also produces a Linking error. Is there any solution for that.



Quote:

> >Eg.

> >class __declspec( dllexport ) InfWindow
> >{
> >protected:
> > static InfTexture*    m_pTexture;    // This can be changed allowing
> >different "styles".
> >public:

>//-------------------------------------------------------------------------
-
> >-----
> > InfWindow();
> > virtual ~InfWindow();
> >public:
> >  INF_RESULT   SetStyle( InfTexture* pTexture );
> >};

>//-------------------------------------------------------------------------
-
> >---------
> >INF_RESULT InfWindow::SetStyle( InfTexture* pTexture )
> >{
> > m_pTexture = pTexture;
> > return INF_OK;
> >}

> >This will give a linking error.

> >Does anyone know how to fix this?

> You have to initialize all static data members:

> InfTexture *InfWindow::m_pTexture = 0;

> This should be done in the file space where you've outlined your
> member function. You can't do that inside any member function.

> HTH

> Chad



Thu, 08 Jul 2004 02:31:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linking Error when using a static variable from a DLL

2. getting link error with static data member

3. C2086 error: static local variables in member functions

4. a static member variable error

5. Export static member variables in DLL

6. static template class member variable in DLL

7. Static Members of a Class + link errors

8. Static smart pointer data member gives link error.

9. Solution: MFC Extension library / static member link errors

10. static data members and link errors

11. Static smart pointer data member gives link error.

12. static function access member variable and member function

 

 
Powered by phpBB® Forum Software