Re: STL question - why does this code crash? by Ben
Ben
Thu Mar 01 09:03:40 CST 2007
in addition, when i compile it from the command line, the resulting
settest.obj file is 109,160 bytes long, whereas from VC++, it's 52,276 bytes
long - i.e. much smaller from within the IDE.
could any of you who have got the same compiler be so kind as to compile the
following with the same switches as I've put below and tell me how big the
obj file is? different from within the IDE as in the command line?
the exact code for settest.cpp is
#include <tchar.h>
#include <set>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
set<int> s;
return 0;
}
"Ben" wrote:
> it's something to do with the way it's compiling it.
> It works fine if I copy the exact same command line
> cl /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm
> /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP
> ".\settest.cpp"
> from the buildlog.htm and paste it into a command window and compile it from
> the command line, then it works fine (regardless of whether I let VC++ link
> it or whether it's linked from the command line).
> The compiler version is the same in each case, "Microsoft (R) 32-bit C/C++
> Optimizing Compiler Version 14.00.50727.42 for 80x86".
>
> any thoughts in the light of this?
>
>
> "Larry Smith" wrote:
>
> > > #include <vector>
> > > #include <set>
> > >
> > > using namespace std;
> > > class c
> > > {
> > > public:
> > > c() {};
> > > virtual ~c() {};
> > > };
> > >
> > > class h : public vector<c>
> > > {
> > > public:
> > > h();
> > > virtual ~h() {};
> > > };
> > >
> > > int _tmain(int argc, _TCHAR* argv[])
> > > {
> > > set<h> myset;
> > >
> > > return 0;
> > > }
> > >
> > >
> > >
> > > it crashes when trying to construct the set, citing 'Stack around the
> > > variable _Hk was corrupted' on line 456 of xtree.
> > >
> > > Any idea what's wrong?
> >
> > Nothing wrong with it that I can see and Alex has confirmed it. In any case,
> > you shouldn't be publicly inheriting from "vector" anyway. As has (probably)
> > been pointed out many times, it has no virtual destructor and it's not
> > generally intended for derivation anyway (though I personally disagree with
> > this philosophy). Note that most classes in the standard library have the
> > same issue.
> >
> >
> >