Re: C2275 compiler error under VS C/C++ 6.0
Doug Harrison [MVP] wrote:
On Tue, 18 Dec 2007 00:35:17 -0500, Pops <notreal@placebo.com> wrote:
What changes I need to make this make this compile under VS C/C++ 6.0?
VC6 has very spotty member template support, and there is no reason for
that function to be a non-static member. You need to make that member
function a non-static member or non-member, but then you're subject to the
VC6 (and 7.0?) bug affecting template parameters that aren't represented in
the function parameter list; the solution to that is to write the function
as:
template <class T>
const XMLCollection<T>
getCollection(T* = 0) const
{
return XMLCollection<T>();
}
Thanks Doug, this is what I ended up doing, but I wasn't sure if it
expands correctly. I'm not a template expert.
This is part of the VSS (Volumne Shadow-copy Service) SDK "TestWriter"
example. According the inline comments, the author coded this
ReadCollection (renamed from WriterConfiguration) class so that its
hidden from the application. It does more than I showed; locks, caching.
So moving it out of the classes (as I explored as well) would change
the implementation drastically.
Perhaps the best solution is to get rid of this superfluous function and
just write XMLColllection<T>() wherever you would call it. I mean, the
function hardly saves you anything! But wait, you actually have a typedef,
so this should be written:
const FileList
excludeFiles() const
{
return FileList();
}
Ok, I see. I was flirting with variations of that too. :-) I had
googled this issue with similar template C2275 errors, some showed
answers where it used the typedef to allocate an instance and then pass
that to the function which returned it after it did some pointer/self
checking. I think I got that to compile too, but wasn't sure if it would
end up the same "template" though.
My apology but I reduced the code for posting purposes, but the real
getCollection member is:
template <class T, wchar_t ElementName[]>
const XMLCollection<T, ElementName> getCollection() const {
assert(m_doc.GetLevel() == 0);
AutoCS critical(m_section);
Resetter reset(m_doc);
if (m_doc.FindElement(ElementName, true))
return XMLCollection<T, ElementName>(m_doc);
else
return XMLCollection<T,ElementName>();
}
And there are various methods for this:
typedef XMLCollection<File, XMLData::ExcludeFile> ExcludeFileList;
typedef XMLCollection<Component, XMLData::Component>ComponentList;
typedef XMLCollection<WriterEvent, XMLData::FailEvent> FailEventList;
const ExcludeFileList excludeFiles() const
{ return getCollection<File, XMLData::ExcludeFile>(); }
const ComponentList components() const
{ return getCollection<Component, XMLData::Component>(); }
const FailEventList failEvents() const
{ return getCollection<WriterEvent, XMLData::FailEvent>(); }
I now have those three as you suggested.
I appreciate your assistance. Thanks.
--