|
Yes, it's perfect. Thank you
|
|
|
|
|
I recently upgraded to Visual Studio 2003 from a version of Visual Studio .Net that is a few years old. After doing so, I converted an old (working) project file to the new version and tried to build.
I'm getting various versions of the same error, and I have no idea what's wrong. My only guess is that it has something to do with the inheritance from std::allocator in class_allocator. I realize its a rather long mess, but this is the first error straight from the build log.
Here's the error, which is basically repeated in various ways about 2000 times:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(25) : error C2248: 'class_allocator<type,blockCount,alignment>::rebind<U>::other' : cannot access inaccessible typedef declared in class 'class_allocator<type,blockCount,alignment>'
with
[
type=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>::value_type,
blockCount=256,
alignment=8,
U=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>::value_type
]
and
[
type=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>::value_type,
blockCount=256,
alignment=8
]
..\clientCommon\Allocator.h(76) : see declaration of 'class_allocator<type,blockCount,alignment>::rebind<U>::other'
with
[
type=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>::value_type,
blockCount=256,
alignment=8,
U=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>::value_type
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(23) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
with
[
_Kty=UString,
_Ty=ResObject *,
_Pr=std::less<UString>,
_Alloc=class_allocator<std::pair<UString,ResObject *>>,
_Mfl=false
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(65) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(87) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(105) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(77) : see reference to class template instantiation 'std::_Tree<_Traits>
' being compiled
with
[
_Traits=std::_Tmap_traits<UString,ResObject *,std::less<UString>,class_allocator<std::pair<UString,ResObject *>>,false>
]
Shell\ResPool.h(71) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
with
[
_Kty=UString,
_Ty=ResObject *,
_Pr=std::less<UString>,
_Alloc=class_allocator<std::pair<UString,ResObject *>>
]
Here's the relevant code:
template< class type, size_t blockCount = 256, size_t alignment = 8 >
class class_allocator : public std::allocator<type>
{
public:
// All of this weirdness is required to make it stl compatible
template <class U> struct rebind { typedef class_allocator<U,blockCount,alignment> other; }; //!< Allow containers to manufacture notes containing node+this
template <class U> class_allocator(const class_allocator<U,blockCount,alignment>&) {} //!< Whatever sort of constructor, this eats them all to provide compatibility
class_allocator() {}
static type* allocate( size_t count = 1, void* = NULL ) { return (type*)pool_allocator<type, sizeof (type), blockCount, alignment>::allocate( count * sizeof (type) ); }
static void deallocate( void* p, size_t = 0 ) { pool_allocator<type, sizeof (type), blockCount, alignment>::deallocate( p ); }
static size_t GetBlockCount() { return pool_allocator<type, sizeof (type), blockCount, alignment>::GetBlockCount(); }
static size_t GetFreeCount() { return pool_allocator<type, sizeof (type), blockCount, alignment>::GetFreeCount(); }
static size_t GetInstanceCount() { return pool_allocator<type, sizeof (type), blockCount, alignment>::GetInstanceCount(); }
};
Does anyone have any idea what's wrong? If not, does anyone have any idea where I could look to find out?
Thanks,
Jon McClure
|
|
|
|
|
My first instinct on looking at the allocator was that most custom allocators I've seen don't inherit from std::allocator, and my second was that maybe throwing in a couple of 'typename's might make the problem go away - but that's a big guess - if my template code gets complicated enough to warrant that I've generally looked for a different approach .
I went through my bookshelf and found some material on writing custom allocators in:
"The C++ Standard Library: A Tutorial and Reference" - Nicolai M. Josuttis (good basic reference)
"Modern C++ Design" - Andrei Alexandrescu (Fixed size allocator + tricks)
"The C++ Programming Language" - Bjarne Stroustrup (pool allocator)
But you're right though, there isn't much good stuff on writing allocators.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Message Removed
modified 29-Jun-21 16:11pm.
|
|
|
|
|
I have a simple function:
void Cell::SetNumber ()
{
cout << "enter";
number= 1;
cout << "exit" ;
}
I get a segment fault after the "enter" prints, and it never seems to leave the routine.number is just an int. What should I suspect?
thanks,
ns
|
|
|
|
|
|
nope. Just using cout.....
|
|
|
|
|
is it possible that the Cell object is not valid ? or the "number" object ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
This is the hundredth time I have made this same mistake.....I say MyClass * ptr, and then blithely do a ptr->method() on it, without having allocated memory which I think is what the problem is here.
Many thanks.
ns
|
|
|
|
|
How is number declared? Could you show more code?
Robert-Antonio
"Life is very hard, when you apply E-R model to it."
|
|
|
|
|
Here's another combo box question for everybody. I have seen some applications where the dropdown menu of a combo box is partitioned into columns separated by a vertical line. How do I create this separate columns, and how do I fill them once they are created? Thanks a ton!!!
|
|
|
|
|
|
In order to use Hadi's suggestion, you'll first need to ensure that the sub dialogs were created with a parent. Otherwise, you'll get the desktop as a parent, ensuring unexpected results!
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
David
where do i set this option..
in the constructor here
CMainDlg(CWnd* pParent = NULL);
??
or is it an option in resource editor class properties
|
|
|
|
|
Irish_GUI wrote:
where do i set this option..
It depends on how you created the CDialog object. Here's an example:
CMainDialog::SomeFunction()
{
CSubDialog Dlg(this);
Dlg.DoModal();
...
CSubDialog *pDlg1;
pDlg1 = new CDialog(this);
pDlg1->Create(IDD_SOMEID);
...
CSubDialog *pDlg2;
pDlg2 = new CDialog;
pDlg2->Create(IDD_SOMEID, this);
}
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
thanks for all your help.
void MainFormDialog::Om_clickmenu()
{
CRemoveFilterDlg dlg2;
dlg2.DoModal();
}
is how im doing it.
When this function is envoked,
a new dialog appears
then the class associated with controlling the CRemoveFilterDlg is in play.
i need to somehow get a pointer from CRemoveFilterDlg
to the data of MainFormDialog
i hope i have explaining it properly.
|
|
|
|
|
Irish_GUI wrote:
CRemoveFilterDlg dlg2;
dlg2 's parent at this point is the desktop, not MainFormDialog .
There are several ways for them to communicate, some better than others. The easiest ways, although I would refrain from using them, would be for the CRemoveFilterDlg class to access it's parent. Something like:
class MainFormDialog : public CDialog
{
public:
int m_nSomeNumber;
};
BOOL CRemoveFilterDlg::OnInitDialog()
{
MainFormDialog *pParent = GetParent();
pParent->m_nSomeNumber = 1234;
} Another approach would be for the parent to access the child:
class CRemoveFilterDlg : public CDialog
{
public:
int m_nYear;
};
void CRemoveFilterDlg::OnOK()
{
dlg2.m_nYear = 2004;
return CDialog::OnOK();
}
void MainFormDialog::Om_clickmenu()
{
CRemoveFilterDlg dlg2;
dlg2.DoModal();
} The problem with these approaches is they completely tie the child dialog to its parent, thus losing all sense of object-ness. If a child dialog needs to talk to its parent or vice-versa, it should do so via posted messages.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
The following situation:
DLL (X) initializes a global variable foo (e.g. a static class member variable)
Application (A) Loads DLL (X)
Application (A) Loads a DLL (B)
DLL (B) loads DLL (X)
do (A) and (B) share the same instance of foo?
(Reading MSDN I think so, but I've never had to rely on this either way)
Flirt harder, I'm a Coder
mlog || Agile Programming | doxygen
|
|
|
|
|
If memory serves me correctly, I think not, as each process will have the DLL mapped in to it's own address space. I believe you can use linker directives to make the segment (that the variable is in) shareable.
Steve S
|
|
|
|
|
Yep, but I'm in the same process (A) which loads both (X) and (B)
(X) is loaded once directly, the second time indirectly via (B)
Flirt harder, I'm a Coder
mlog || Agile Programming | doxygen
|
|
|
|
|
Typically Yes, And i figure out why not. Dll accupies a memory space and is not loaded again, so Application A and DLL B will have the same instance handle of the DLL X. And the corresponding value of the static variable will be accessible.
This is similar to what reference count is all about in inproc COM dll.
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
No. Each process gets it owns instance of the global variables inside DLL.
Kuphryn
|
|
|
|
|
Yes, a DLL can only be loaded once into a process. If you try to load it again, all that happens is the DLL's ref count is increased. Since there is only one instance of DLL X in the process, there is only one foo.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
peterchen wrote:
do (A) and (B) share the same instance of foo?
According to this article[^], only the code is shared. Each instance of the DLL gets its own data segment. The article cited above explains how to get around this issue.
Good Luck!
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
Netmeisters,
I am trying to use the Canon SDK from a C++ project. The SDK declares callbacks as
cdUInt32 cdSTDCALL MyEventCallbackFunction (etc)
{
}
and the callback is installed as:
CDRegisterEventCallbackFunction(
....
&MyEventCallbackFunction,
....)
Here, cdUInt32 is just a typedef for UInt32, and cdSTDCALL seems to be a typedef for __stdcall.
The problem is that I am using C++, so want to use a member function for the callback. I.e., something like
cdUInt32 MyClass::MyEventCallbackFunction
but this seems not to work.
Is there any way of getting it to work?
Your suggestions much appreciated.
|
|
|
|
|