what is wrong here? (templates)

G

Guest

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
 
L

Leor Zolman

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)

Shared said:
{
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 said:
{
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
 
G

Gianni Mariani

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 said:
{
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 said:
{
for (unsigned int z = 0; z < pointers.size(); z++)
....

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

Rob Williscroft

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)


}

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


}

HTH.

Rob.
 
G

Guest

What idiot I am ;-)

void SharedObject<C>::GarbageCollector()
instead of
void SharedObject::GarbageCollector()


Sorry for this silly post...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top