struct in class -> problem...

This is a discussion on struct in class -> problem... within the C++ Programming forums, part of the General Programming Boards category; I have a class, and that class contains an struct. but i am having problems returning the struct to main ...

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

    struct in class -> problem...

    I have a class, and that class contains an struct. but i am having problems returning the struct to main and read out the values the right way!.

    Code:
    void member::setgroup (Group thegroup)
    {
      TypeAcc = thegroup;
      std::cout << TypeAcc.Type << std::endl;
      std::cout << TypeAcc.CheckNum << std::endl;
    
    } //setgroup function, everything works fine here.
    Code:
    Group       member::getgroup    ()  { return (TypeAcc); }// the problem?
    Code:
    int main ()
    {
      Group Newgroup;
      Newgroup.Type = CharGroup[0] ;
      Newgroup.CheckNum = ADMIN;
      std::cout << Newgroup.Type <<"\n"<< Newgroup.CheckNum << std::endl;
      member admin ("KaK","sven_v45@hotmail.com",16,Newgroup );
      Group N;
      admin.getgroup()  = N; // might be here...
      std::cout << N.Type <<"\n"<< N.CheckNum << std::endl;
      return 0;
    }
    output :

    C:\Documents and
    Code:
    Settings\Sven\cbproject\ConsoleApp1\windows\Debug_Build\ConsoleApp1.exe
    ADMIN        -> GOOD
    1                -> GOOD
    ADMIN        -> GOOD // these are the output functions called inside setgroup
    1                -> GOOD
                      -> BAD  // this is faulty, did i return TypeAcc wrong?
    8                -> BAD // same

    well, its got me wondering...

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,012
    It should be:
    Code:
     N = admin.getgroup();
    Not vice versa.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    got dammit that was stupid.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  3. Class Membership Problem
    By josephjah in forum C++ Programming
    Replies: 5
    Last Post: 05-27-2007, 01:48 PM
  4. const elements of struct / class not accessible?
    By talz13 in forum C# Programming
    Replies: 2
    Last Post: 03-24-2006, 04:05 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21