By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

what is wrong here? (templates)

P: n/a
I have these errors with code following:
---------------------------------------------------------------
'SharedObject' : use of class template requires template argument list
'SharedObject<C>::checkEquality' : unable to match function definition to an existing declaration
'SharedObject<C>::GarbageCollector' : unable to match function definition to an existing declaration
---------------------------------------------------------------
#ifndef SHARED_OBJECT_H
#define SHARED_OBJECT_H
template <class C>
struct Shared
{
unsigned int count;
C data;
};

template <class C>
class SharedObject
{
public:
static void GarbageCollector();

protected:
Shared<C> *pointer;
static vector <Shared<C>*> pointers;

static Shared<C> *checkEquality(C &c);
};
template <class C>
Shared<C> *SharedObject::checkEquality(C &c)
{
for (int z = 0; z < (signed) pointers.size(); z++)
if (pointers[z]->count && c == pointers[z]->data) return pointers[z];
return 0;
}

template <class C>
void SharedObject::GarbageCollector()
{
for (unsigned int z = 0; z < pointers.size(); z++)
if (!pointers[z]->count)
{
delete pointers[z];
pointers[z] = pointers.back();
pointers.pop_back();
z--;
}
}

#endif // SHARED_OBJECT_H
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sat, 8 May 2004 18:07:09 +0300, "<- Chameleon ->"
<ch******@hotmail.NOSPAM.com> wrote:
I have these errors with code following:
---------------------------------------------------------------
'SharedObject' : use of class template requires template argument list
'SharedObject<C>::checkEquality' : unable to match function definition to an existing declaration
'SharedObject<C>::GarbageCollector' : unable to match function definition to an existing declaration
---------------------------------------------------------------
#ifndef SHARED_OBJECT_H
#define SHARED_OBJECT_H
#include <vector> // and use std:: on vector below, preferable to
// "using" in a header


template <class C>
struct Shared
{
unsigned int count;
C data;
};

template <class C>
class SharedObject
{
public:
static void GarbageCollector();

protected:
Shared<C> *pointer;
static vector <Shared<C>*> pointers;

static Shared<C> *checkEquality(C &c);
};
template <class C>
Shared<C> *SharedObject::checkEquality(C &c)
Shared<C> *SharedObject<C>::checkEquality(C &c)
{
for (int z = 0; z < (signed) pointers.size(); z++)
if (pointers[z]->count && c == pointers[z]->data) return pointers[z];
return 0;
}

template <class C>
void SharedObject::GarbageCollector()
void SharedObject<C>::GarbageCollector()
{
for (unsigned int z = 0; z < pointers.size(); z++)
if (!pointers[z]->count)
{
delete pointers[z];
pointers[z] = pointers.back();
pointers.pop_back();
z--;
}
}

#endif // SHARED_OBJECT_H


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2

P: n/a
<- Chameleon -> wrote:
I have these errors with code following:
---------------------------------------------------------------
'SharedObject' : use of class template requires template argument list
'SharedObject<C>::checkEquality' : unable to match function definition to an existing declaration
'SharedObject<C>::GarbageCollector' : unable to match function definition to an existing declaration
--------------------------------------------------------------- .... Shared<C> *SharedObject::checkEquality(C &c)
Shared<C> *SharedObject<C>::checkEquality(C &c)
{
for (int z = 0; z < (signed) pointers.size(); z++)
if (pointers[z]->count && c == pointers[z]->data) return pointers[z];
return 0;
}

template <class C>
void SharedObject::GarbageCollector()
void SharedObject<C>::GarbageCollector()
{
for (unsigned int z = 0; z < pointers.size(); z++)

....

I made the changes above ant it compiled fine under gcc 3.3.1

Jul 22 '05 #3

P: n/a
<- Chameleon -> wrote in news:c7**********@nic.grnet.gr in
comp.lang.c++:
I have these errors with code following:
---------------------------------------------------------------
'SharedObject' : use of class template requires template argument list
'SharedObject<C>::checkEquality' : unable to match function definition
to an existing declaration 'SharedObject<C>::GarbageCollector' :
unable to match function definition to an existing declaration
---------------------------------------------------------------
template <class C>
class SharedObject
{
public:
static void GarbageCollector();
static Shared<C> *checkEquality(C &c);
};
template <class C>
Shared<C> *SharedObject::checkEquality(C &c)
Shared<C> *SharedObject< C >::checkEquality(C &c)

{ }

template <class C>
void SharedObject::GarbageCollector()
void SharedObject< C >::GarbageCollector()

{ }


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4

P: n/a
What idiot I am ;-)

void SharedObject<C>::GarbageCollector()
instead of
void SharedObject::GarbageCollector()
Sorry for this silly post...

I have these errors with code following:
---------------------------------------------------------------
'SharedObject' : use of class template requires template argument list
'SharedObject<C>::checkEquality' : unable to match function definition to an existing declaration
'SharedObject<C>::GarbageCollector' : unable to match function definition to an existing declaration
---------------------------------------------------------------
#ifndef SHARED_OBJECT_H
#define SHARED_OBJECT_H
template <class C>
struct Shared
{
unsigned int count;
C data;
};

template <class C>
class SharedObject
{
public:
static void GarbageCollector();

protected:
Shared<C> *pointer;
static vector <Shared<C>*> pointers;

static Shared<C> *checkEquality(C &c);
};
template <class C>
Shared<C> *SharedObject::checkEquality(C &c)
{
for (int z = 0; z < (signed) pointers.size(); z++)
if (pointers[z]->count && c == pointers[z]->data) return pointers[z];
return 0;
}

template <class C>
void SharedObject::GarbageCollector()
{
for (unsigned int z = 0; z < pointers.size(); z++)
if (!pointers[z]->count)
{
delete pointers[z];
pointers[z] = pointers.back();
pointers.pop_back();
z--;
}
}

#endif // SHARED_OBJECT_H

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.