|
|
 |
Author |
Message |
apolter

|
Posted: Sun Apr 10 19:35:52 CDT 2005 |
Top |
Visual Studio C++ >> Use of typename
Can anyone help with the following use of the typename keyword?
When I compile this class:
//SDBObject.h
#pragma once
using namespace std;
template<class SDBObjectT> class SDBContainer : private set<SDBObjectT>
{
protected:
map<HANDLE,string> Lookup;
public:
typedef set<SDBObjectT> constiterator;
SDBContainer() {};
virtual ~SDBContainer() {};
set<SDBObjectT>::const_iterator AddItem(const SDBObjectT& newitem) const;
set<SDBObjectT>::const_iterator operator[](const string&) const {return
NULL;};
};
//SDBObject.cpp
#include "stdafx.h"
#include "SDBContainer.h"
using namespace std;
template<class SDBObjectT>
typename set<SDBObjectT>::const_iterator
SDBContainer<SDBObjectT>::AddItem(const SDBObjectT& newitem) const
{
//...
}
#include "SDBObject.h"
template SDBContainer<SDBObject>;
I get this error:
Compiling...
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.40607.16 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.
cl /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1 /MTd
/GS /GR /Yu"stdafx.h" /Fp"Debug/sqldbg.pch" /Fo"Debug/" /Fd"Debug/vc80.pdb"
/W3 /c /Wp64 /Zi /TP -DISOLATION_AWARE_ENABLED
".\SDBContainer.cpp"
SDBContainer.cpp
SDBContainer.cpp(9) : error C2244: 'SDBContainer<SDBObjectT>::AddItem' :
unable to match function definition to an existing declaration
c:\Documents and Settings\Bonj\My
Documents\Projects\...\SDBContainer.h(12) : see declaration of
'SDBContainer<SDBObjectT>::AddItem'
definition
'set<SDBObjectT>::const_iterator
SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
existing declarations
'std::_Tree<SDBObjectT>::const_iterator
SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
Build log was saved at "file://c:\Documents and Settings\Bonj\My
Documents\Projects\...\Debug\BuildLog.htm"
sqldbg - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It's splitting AddItem out into a .cpp file that's causing the problems - it
works ok with the class methods all in a header file, but i'd rather split
it out if possible. It seems to be confusing
"set<SDBObjectT>::const_iterator" for
"std::_Tree<SDBObjectT>::const_iterator" ... ?
I need to return a pointer (the target of which won't need to be modified
but will need to be read) to the object added so returning a type of the
const_iterator of the underlying set seems right, but it won't compile. Any
ideas?
Visual Studio46
|
|
|
|
 |
Bonj

|
Posted: Sun Apr 10 19:35:52 CDT 2005 |
Top |
Visual Studio C++ >> Use of typename
Oh, i've worked it out don't worry
> Can anyone help with the following use of the typename keyword?
> When I compile this class:
> //SDBObject.h
> #pragma once
>
> using namespace std;
> template<class SDBObjectT> class SDBContainer : private set<SDBObjectT>
> {
> protected:
> map<HANDLE,string> Lookup;
> public:
> typedef set<SDBObjectT> constiterator;
> SDBContainer() {};
> virtual ~SDBContainer() {};
> set<SDBObjectT>::const_iterator AddItem(const SDBObjectT& newitem) const;
> set<SDBObjectT>::const_iterator operator[](const string&) const {return
> NULL;};
> };
> //SDBObject.cpp
> #include "stdafx.h"
> #include "SDBContainer.h"
> using namespace std;
>
> template<class SDBObjectT>
> typename set<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT& newitem) const
> {
> //...
> }
>
> #include "SDBObject.h"
> template SDBContainer<SDBObject>;
>
> I get this error:
> Compiling...
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.40607.16 for
> 80x86
> Copyright (C) Microsoft Corporation. All rights reserved.
> cl /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1
> /MTd /GS /GR /Yu"stdafx.h" /Fp"Debug/sqldbg.pch" /Fo"Debug/"
> /Fd"Debug/vc80.pdb" /W3 /c /Wp64 /Zi /TP -DISOLATION_AWARE_ENABLED
>
> ".\SDBContainer.cpp"
> SDBContainer.cpp
> SDBContainer.cpp(9) : error C2244: 'SDBContainer<SDBObjectT>::AddItem' :
> unable to match function definition to an existing declaration
> c:\Documents and Settings\Bonj\My
> Documents\Projects\...\SDBContainer.h(12) : see declaration of
> 'SDBContainer<SDBObjectT>::AddItem'
> definition
> 'set<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
> existing declarations
> 'std::_Tree<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
> Build log was saved at "file://c:\Documents and Settings\Bonj\My
> Documents\Projects\...\Debug\BuildLog.htm"
> sqldbg - 1 error(s), 0 warning(s)
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
> ==========
>
>
> It's splitting AddItem out into a .cpp file that's causing the problems -
> it works ok with the class methods all in a header file, but i'd rather
> split it out if possible. It seems to be confusing
> "set<SDBObjectT>::const_iterator" for
> "std::_Tree<SDBObjectT>::const_iterator" ... ?
> I need to return a pointer (the target of which won't need to be modified
> but will need to be read) to the object added so returning a type of the
> const_iterator of the underlying set seems right, but it won't compile.
> Any ideas?
>
>
|
|
|
|
 |
Bonj

|
Posted: Sun Apr 10 19:45:48 CDT 2005 |
Top |
Visual Studio C++ >> Use of typename
The resolution was seemingly to put
typename SDBContainer<SDBObject>::const_iterator
rather than
typename set<SDBObject>::const_iterator
in the cpp file.
But I still don't get why that was necessary, and why it reverted to '_Tree'
before?
> Oh, i've worked it out don't worry
>
>> Can anyone help with the following use of the typename keyword?
>> When I compile this class:
>> //SDBObject.h
>> #pragma once
>>
>> using namespace std;
>> template<class SDBObjectT> class SDBContainer : private set<SDBObjectT>
>> {
>> protected:
>> map<HANDLE,string> Lookup;
>> public:
>> typedef set<SDBObjectT> constiterator;
>> SDBContainer() {};
>> virtual ~SDBContainer() {};
>> set<SDBObjectT>::const_iterator AddItem(const SDBObjectT& newitem) const;
>> set<SDBObjectT>::const_iterator operator[](const string&) const {return
>> NULL;};
>> };
>> //SDBObject.cpp
>> #include "stdafx.h"
>> #include "SDBContainer.h"
>> using namespace std;
>>
>> template<class SDBObjectT>
>> typename set<SDBObjectT>::const_iterator
>> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT& newitem) const
>> {
>> //...
>> }
>>
>> #include "SDBObject.h"
>> template SDBContainer<SDBObject>;
>>
>> I get this error:
>> Compiling...
>> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.40607.16 for
>> 80x86
>> Copyright (C) Microsoft Corporation. All rights reserved.
>> cl /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1
>> /MTd /GS /GR /Yu"stdafx.h" /Fp"Debug/sqldbg.pch" /Fo"Debug/"
>> /Fd"Debug/vc80.pdb" /W3 /c /Wp64 /Zi /TP -DISOLATION_AWARE_ENABLED
>>
>> ".\SDBContainer.cpp"
>> SDBContainer.cpp
>> SDBContainer.cpp(9) : error C2244: 'SDBContainer<SDBObjectT>::AddItem' :
>> unable to match function definition to an existing declaration
>> c:\Documents and Settings\Bonj\My
>> Documents\Projects\...\SDBContainer.h(12) : see declaration of
>> 'SDBContainer<SDBObjectT>::AddItem'
>> definition
>> 'set<SDBObjectT>::const_iterator
>> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
>> existing declarations
>> 'std::_Tree<SDBObjectT>::const_iterator
>> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
>> Build log was saved at "file://c:\Documents and Settings\Bonj\My
>> Documents\Projects\...\Debug\BuildLog.htm"
>> sqldbg - 1 error(s), 0 warning(s)
>> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
>> ==========
>>
>>
>> It's splitting AddItem out into a .cpp file that's causing the problems -
>> it works ok with the class methods all in a header file, but i'd rather
>> split it out if possible. It seems to be confusing
>> "set<SDBObjectT>::const_iterator" for
>> "std::_Tree<SDBObjectT>::const_iterator" ... ?
>> I need to return a pointer (the target of which won't need to be modified
>> but will need to be read) to the object added so returning a type of the
>> const_iterator of the underlying set seems right, but it won't compile.
>> Any ideas?
>>
>>
>
>
|
|
|
|
 |
Tim

|
Posted: Thu Apr 14 14:05:37 CDT 2005 |
Top |
Visual Studio C++ >> Use of typename
SDBContainer<SDBObjectT>::AddItem
should be :
SDBContainer<class SDBObjectT>::AddItem
Tim Tian
> Can anyone help with the following use of the typename keyword?
> When I compile this class:
> //SDBObject.h
> #pragma once
>
> using namespace std;
> template<class SDBObjectT> class SDBContainer : private set<SDBObjectT>
> {
> protected:
> map<HANDLE,string> Lookup;
> public:
> typedef set<SDBObjectT> constiterator;
> SDBContainer() {};
> virtual ~SDBContainer() {};
> set<SDBObjectT>::const_iterator AddItem(const SDBObjectT& newitem) const;
> set<SDBObjectT>::const_iterator operator[](const string&) const {return
> NULL;};
> };
> //SDBObject.cpp
> #include "stdafx.h"
> #include "SDBContainer.h"
> using namespace std;
>
> template<class SDBObjectT>
> typename set<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT& newitem) const
> {
> //...
> }
>
> #include "SDBObject.h"
> template SDBContainer<SDBObject>;
>
> I get this error:
> Compiling...
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.40607.16 for
> 80x86
> Copyright (C) Microsoft Corporation. All rights reserved.
> cl /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1
/MTd
> /GS /GR /Yu"stdafx.h" /Fp"Debug/sqldbg.pch" /Fo"Debug/"
/Fd"Debug/vc80.pdb"
> /W3 /c /Wp64 /Zi /TP -DISOLATION_AWARE_ENABLED
>
> ".\SDBContainer.cpp"
> SDBContainer.cpp
> SDBContainer.cpp(9) : error C2244: 'SDBContainer<SDBObjectT>::AddItem' :
> unable to match function definition to an existing declaration
> c:\Documents and Settings\Bonj\My
> Documents\Projects\...\SDBContainer.h(12) : see declaration of
> 'SDBContainer<SDBObjectT>::AddItem'
> definition
> 'set<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
> existing declarations
> 'std::_Tree<SDBObjectT>::const_iterator
> SDBContainer<SDBObjectT>::AddItem(const SDBObjectT &) const'
> Build log was saved at "file://c:\Documents and Settings\Bonj\My
> Documents\Projects\...\Debug\BuildLog.htm"
> sqldbg - 1 error(s), 0 warning(s)
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
>
>
> It's splitting AddItem out into a .cpp file that's causing the problems -
it
> works ok with the class methods all in a header file, but i'd rather split
> it out if possible. It seems to be confusing
> "set<SDBObjectT>::const_iterator" for
> "std::_Tree<SDBObjectT>::const_iterator" ... ?
> I need to return a pointer (the target of which won't need to be modified
> but will need to be read) to the object added so returning a type of the
> const_iterator of the underlying set seems right, but it won't compile.
Any
> ideas?
>
>
|
|
|
|
 |
|
|