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:46:24 GMT  
 about struct problem!Please help me!

You are not declaring it correctly. Try this:
static config SomeConfig; // (not StruInit)


  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 !



Fri, 17 Sep 2004 18:54:33 GMT  
 about struct problem!Please help me!
If I understand the code correctly (been a while since I've done stuff with
structs), having the "StruInit;" part after the close of the struct
definition declares StruInit as a member of the type of the struct. The next
line, you try to define a member with the same name, this time making it
static.

If you just remove the StruInit from the end of the struct definition, it
should work.

Unless I'm all horribly mistaken :P

Niall



Fri, 17 Sep 2004 18:59:48 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 !

Or try this:

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

 } config;

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

Quote:
};

/johan


Fri, 17 Sep 2004 20:52:03 GMT  
 
 [ 4 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