Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

Template question


I have a template class declared like this:

template <class T>
class CKineStore
{
public:
        CKineStore(void) {};
        virtual ~CKineStore(void) {};

public:
        void    Insert(CKineTypes::ECKineType type, T&);

private:
        typedef std::pair <CKineTypes::ECKineType, T> m_pair;
        typedef std::map <CKineTypes::ECKineType, T> m_map;

};

template <class T> void CKineStore<T>::Insert(CKineTypes::ECKineType
type, T& t)
{
        m_map.insert(m_pair(type, t));

}

If I dont call Insert() it compiles okay, but when I call it I get an
unresolved external symbol error.  What am I doing wrong?

Thanks,
B

On Jun 3, 6:36 pm, Bryan <b@no.spam.com> wrote:

You didn't provide much information about CKineTypes, nonetheless,
try:

void    Insert( typename CKineTypes::ECKineType type, T&);
template <class T>
void CKineStore<T>::Insert(
  typename CKineTypes::ECKineType
  type, T& t)
{}

Note the use of "typename"

ma740988 wrote:

> You didn't provide much information about CKineTypes, nonetheless,
> try:

> void    Insert( typename CKineTypes::ECKineType type, T&);
> template <class T>
> void CKineStore<T>::Insert(
>   typename CKineTypes::ECKineType
>   type, T& t)
> {}

> Note the use of "typename"

Sorry, CKineTypes is just an enum.

Still the same error though.  I did this:
template <class T>
class CKineStore
{
...
public:
        void    Insert(typename CKineTypes::ECKineType type, T&);
...

};

And in the cpp file:
template <class T>
void CKineStore<T>::Insert(typename CKineTypes::ECKineType type, T& t)
{
        insert(m_pair(type, t));

}

Im not very experienced with templates obviously, what am I missing?

B

Bryan wrote:
> I have a template class declared like this:

> template <class T>
> class CKineStore
> {
> public:
>     CKineStore(void) {};

Why the void? This isn't C.

>     virtual ~CKineStore(void) {};

> public:
>     void    Insert(CKineTypes::ECKineType type, T&);

What is CKineTypes and its ECKineType? Why this need for hungarian
notation (prefixing type names with a C and E)?

> private:
>     typedef std::pair <CKineTypes::ECKineType, T> m_pair;
>     typedef std::map <CKineTypes::ECKineType, T> m_map;

Here, m_map is defined as a type.

> };

> template <class T> void CKineStore<T>::Insert(CKineTypes::ECKineType
> type, T& t)
> {
>     m_map.insert(m_pair(type, t));

Here, you are using m_map, the type, as an object.

> }

> If I dont call Insert() it compiles okay, but when I call it I get an
> unresolved external symbol error.  What am I doing wrong?

Try removing the typedef in m_map's definition.

--
rbh

Robert Bauck Hamar wrote:
> Bryan wrote:
>> I have a template class declared like this:

>> template <class T>
>> class CKineStore
>> {
>> public:
>>     CKineStore(void) {};

> Why the void? This isn't C.

Dunno.  Visual studio 2005 sticks it in there by default.

>>     virtual ~CKineStore(void) {};

>> public:
>>     void    Insert(CKineTypes::ECKineType type, T&);

> What is CKineTypes and its ECKineType? Why this need for hungarian
> notation (prefixing type names with a C and E)?

CKineTypes is actually not hungarian, but you are right ECKineType is.
I am just used to it I suppose.

>> private:
>>     typedef std::pair <CKineTypes::ECKineType, T> m_pair;
>>     typedef std::map <CKineTypes::ECKineType, T> m_map;

> Here, m_map is defined as a type.

You are right, this is a typo on my part.  It is actually:
        std::map <CKineTypes::ECKineType, T> m_map;

This is a larger class, and I removed some portions for brevity.

Error seems to persist... the errors you pointed out are valid- not
complaining at all, thanks for pointing them out.

But the error I initially reported is a signature issue.  The
declaration of the Insert function doesnt match any known definition, so
the unresolved external symbol error shows up.

I can, in fact do this:
template <class T>
class CKineStore
{
...
public:
     void    Test();
...

};

template <class T>
void CKineStore<T>::Test()
{

}

And I get the same error, unresolved external symbol.
On Jun 4, 1:52 am, Bryan <b@no.spam.com> wrote:

> And in the cpp file:
> template <class T>
> void CKineStore<T>::Insert(typename CKineTypes::ECKineType type, T& t)
> {
>         insert(m_pair(type, t));

> }

> Im not very experienced with templates obviously, what am I missing?

Try putting everything in the same file.

v.r.mari@gmail.com wrote:
> On Jun 4, 1:52 am, Bryan <b@no.spam.com> wrote:

>> And in the cpp file:
>> template <class T>
>> void CKineStore<T>::Insert(typename CKineTypes::ECKineType type, T& t)
>> {
>>         insert(m_pair(type, t));

>> }

>> Im not very experienced with templates obviously, what am I missing?

> Try putting everything in the same file.

That did it!

Thanks,
B

Compiles with my compiler, but I use g++. The only explanation I can
think of, is that the compiler can't see the definition of
CKineStore<T>::Test(). The definition is, of course, included together
with the CKineStore class declaration? Then again, it's five in the
morning here, so I'm beginning to feel tired.

--
rbh

On Jun 4, 6:08 am, Robert Bauck Hamar <hamro@yahoo.no> wrote:

If the definition wasn't included you would have a link error.
This is not compiler dependent issue.

BTW some compilers like Cameau (and Intel?) support exported
templates.
The *export* keyword is part of the standard, but neither g++ nor vc++
support it.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc