• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: STL set inside inside a class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: STL set inside inside a class


  • Subject: Re: STL set inside inside a class
  • From: Paul Forgey <email@hidden>
  • Date: Wed, 17 May 2006 15:41:49 -0700

What you are doing seems fine. Maybe you invoked GenericTree::CalcDepthRecursive with a bogus this pointer? Quite often unexplained crashes in member variables' class methods can be traced back to the original class instance being invalid.

The rest is off topic but it will make your life easier..

You don't need to first check if a map member is already there before doing the ++. The operator[] will insert a default value for the type at the key if it doesn't exist and then return a reference to it. That means depthCount[depth]++ will always do what you expect since the default instantiation of a simple scaler type is 0.

Also if you use typedefs:

class GenericTree {
    ..
    typedef std::map< const int, UInt16 > depthcount_type;
    ..
    depthcount_type depthCount;
    ..
};

Then you don't have to keep saying std::map< const int, UInt16 >::whatever_type all the time.

On May 17, 2006, at 2:48 PM, mark wrote:

Hello.

I have a class with a set defined in it.

class GenericTree {
TreeObjectRef *toBlock; // 0 is usually the root
UInt16 refCount;
UInt16 maxItems;
void* root;
UInt16 itemCount;
std::map<const int, UInt16> depthCount; // number of objects at depth X
...
}


And a method in the class

void GenericTree::CalcDepthRecursive(SInt16 index, SInt16 depth) {
      UInt16 t;
        if (depth>maxDepth) {return;}
        ...
        std::map<const int, UInt16>::iterator end=depthCount.end();
     if (depthCount.find(depth)!=end) {
              depthCount[depth]++;
            }
       else {
                depthCount[depth]=1; (1)
                }
        ...
        };
}
(1) causes an EXC_BAD_ACCESS somewhere deep inside the bowels of set.
If the depthCount is not in a class, it works fine,

operator--()
      {
     _M_node = _Rb_tree_decrement(_M_node); <<< here
return *this;
      }

Is this an implementation issue for set or doesn't set like living inside a class?
I have only started using STL receently.
XCode 2.2.1, OS 10.4.6


TIA
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40aphrodite.com


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: STL set inside inside a class
      • From: Jan Brittenson <email@hidden>
References: 
 >STL set inside inside a class (From: mark <email@hidden>)

  • Prev by Date: Re: Find Fast
  • Next by Date: Re: dead-code stripping, pass two...
  • Previous by thread: STL set inside inside a class
  • Next by thread: Re: STL set inside inside a class
  • Index(es):
    • Date
    • Thread