CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    7

    How to initialize structures inside a class?

    How do u initialize a structure inside a class e.g
    class Mail
    {
    public:
    struct VM{
    char current[20];
    char dtmf;
    char next[20];
    void (*ifptr)(int,int);
    };
    typedef VM VMail;
    VMail Mailme[] = {
    { "qq", 'd', "ww", Function1},
    { "aa", 'w', "eee", Function2},
    };
    }

    The compiler cannot recognize the initialization here. How do i put this part of the initialization code in the constructor?
    VMail Mailme[] = {
    { "qq", 'd', "ww", Function1},
    { "aa", 'w', "eee", Function2},
    };
    I already tried putting it in the constructor but it still cannot work. How else can i initialize my structure?

    Thanks



  2. #2
    Join Date
    Apr 1999
    Posts
    306

    Re: How to initialize structures inside a class?

    I do not know if this is the problem, but if I had to do this I would do it like this:

    // Just declare globally
    typedef struct VM{
    char current[20];
    char dtmf;
    char next[20];
    void (*ifptr)(int,int);
    } VMail;

    Class Mail
    {
    VMail mail[2];

    };

    void Mail::Mail()
    {
    mail[0].string = "Hello";
    ......
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured