about struct problem!Please help me! 
Author Message
 about struct problem!Please help me!

Hi:
    I wrote a head file,the source is:

class CConfig : public CObject
{
public:
 void initConfig();
 CConfig();
 virtual ~CConfig();
 struct config              // Declare StruInit struct type
{
   CString  connDb;
   CString loginName;
   CString Password;
   int  interval; // the unit is second
   CString ServerAddress;
   UINT  ServerPort;

Quote:
} StruInit;

 static config StruInit;
 private:
 bool getInitFile(LPCTSTR filePath);
 CStdioFile f;
 CFileException e;

Quote:
};

    Please notice the red word ,I want a global var.
    When I compile the file ,the error is :  "error C2370: 'StruInit' :
redefinition; different storage class"
    Can you tell me why ?
    Thanks !


Fri, 17 Sep 2004 16:47:18 GMT  
 about struct problem!Please help me!

Quote:

> Hi:
>     I wrote a head file,the source is:

> class CConfig : public CObject
> {
> public:
>  void initConfig();
>  CConfig();
>  virtual ~CConfig();
>  struct config              // Declare StruInit struct type
> {
>    CString  connDb;
>    CString loginName;
>    CString Password;
>    int  interval; // the unit is second
>    CString ServerAddress;
>    UINT  ServerPort;

> } StruInit;
>  static config StruInit;
>  private:
>  bool getInitFile(LPCTSTR filePath);
>  CStdioFile f;
>  CFileException e;
> };

>     Please notice the red word ,I want a global var.
>     When I compile the file ,the error is :  "error C2370: 'StruInit' :
> redefinition; different storage class"
>     Can you tell me why ?
>     Thanks !

Yes, you've declared one class instance config struct named StruInit and one static
CConfig::StruInit config struct ("redefinition"). The both have the same name but one is static and
one isn't ("different storage class"). How many of them do you intend to have?

Jeff...



Fri, 17 Sep 2004 20:19:36 GMT  
 about struct problem!Please help me!
Quote:
>     I wrote a head file,the source is:

> class CConfig : public CObject
> {
> public:
>  void initConfig();
>  CConfig();
>  virtual ~CConfig();
>  struct config              // Declare StruInit struct type
> {
>    CString  connDb;
>    CString loginName;
>    CString Password;
>    int  interval; // the unit is second
>    CString ServerAddress;
>    UINT  ServerPort;

> } StruInit;
    ^^^^^^^^
>  static config StruInit;

                 ^^^^^^^^
Quote:

>     Please notice the red word ,I want a global var.
>     When I compile the file ,the error is :  "error C2370: 'StruInit' :
> redefinition; different storage class"
>     Can you tell me why ?

Because StruInit defined twice. You should write

struct config {
...

Quote:
}; // nothing here

static config StruInit;


Fri, 17 Sep 2004 20:37:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. struct problem, please help

2. about struct problem!Please help me!

3. New2C: Problems understanding STRUCT Please HELP!!!!

4. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

5. Please help!!!!Please help!!!!Please help!!!!

6. Pointer to struct function NEWBIE PLEASE HELP

7. Struct memory layout, please help!

8. Pointer to a struct within an array Help Please

9. struct help please..

10. Struct Newbie!! Help please

11. Struct.....Help Please!!

12. Please help me with Pointers and Structs

 

 
Powered by phpBB® Forum Software