Thread: static data members in structure

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    18

    static data members in structure

    Hi everybody!

    I am in great trouble regarding structures.It is as follow:-

    I am developing a DLL in C++ using VC++ editor.This DLL is called by the another C++

    programme to achive some functonality.

    I declared a structure as follow:

    Code:
    typedef struct{
    
     static char szOriginalAddress[0x100];
     static char szRecipientAddress[0x100];
     static char szFileName[0x100];
    
    } TExternalFilter;
    
    #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
    no_namespace rename ("EOF", "ADOEOF")
    
    
    EXPORT DWORD Filter(TExternalFilter* );
    
    This is header file in which declaration has been done.
    
    The programme in which this header file is used  is as follow:-
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved	 )
    {
        return TRUE;
    }
    
    
    EXPORT DWORD Filter(TExternalFilter* ExternalFilter)
    {		
    	static char temp[256];	
    	strcpy(temp,ExternalFilter->szOriginalAddress);
    }
    This file is called by our main CPP program.

    When i compile this program it gives following Linker error in DLL:
    error LNK2001: unresolved external symbol "public: static char * __unnamed::szOriginalAddress" (?szOriginalAddress@__unnamed@@2PADA)


    This error is due to variable are declare as static in DLL, but I want these member as

    static only.Please tell me what code and where should I implement so that I can remove this

    problem.

    Added : How can I declare and define these static member variables? The linker error may be due to static variables not being defiined but only declared.


    Please help in solving this problem.

    I will be very thankful.

    Thanks in advanced

    Bhagwat
    Last edited by bhagwat_maimt; 11-06-2006 at 01:19 AM.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Static data members need to be defined outside the class body. Currently they just have a declaration.

    Create a cpp file, #include this header, and add the following:

    Code:
    static char TExternalFilter::szOriginalAddress[0x100];
    static char TExternalFilter::szRecipientAddress[0x100];
    static char TExternalFilter::szFileName[0x100];
    Now the static data of the TExternalFilter class is properly defined.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Mario F., it's a structure
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I confess I'm not used to that style. But...
    Code:
    typedef struct {} foo;
    Is the same as
    struct foo {};
    Isn't it?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You were talking about class.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Ah. Gotcha!

    a struct is a class... at least on this forum
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by Mario F.
    I confess I'm not used to that style. But...
    Code:
    typedef struct {} foo;
    Is the same as
    struct foo {};
    Isn't it?
    In C++, yes.

    In C, there are syntax differences in how you'd use them, pass them to functions, etc.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    18

    declaring and intializing static variables

    Thanks for your reply!

    How can I declare and define these static member variables? The linker error may be due to static variables not being defiined but only declared.
    Waiting for your reply .

    Thanks

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I really don't think you actually want these to be static.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User zouyu1983's Avatar
    Join Date
    Nov 2006
    Location
    Fuzhou University, Fujian, China
    Posts
    35
    In c++, the structure is the class except the default access control
    In class , is private
    In structure, is public

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM