473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

what is wrong here? (templates)

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
4 5954
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
<- 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
<- 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: PassingBy | last post by:
I recently came across a template site selling cd's and was wondering what the groups opinion is of this? I purchased one of the cd's and the templates are great and Im looking forward to...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
4
by: Pete | last post by:
If anyone here can tell me what's going wrong in this snippet, I'd be much obliged. It works under g++ 3.3 but not the (fussier) g++ 3.4. Thanks... template<typename T> struct base { T...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
2
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
10
by: andrew browning | last post by:
i have overlaoded all of my arithmetic operators but all are functioning as multiplication. below is a sample of the addition operator: Rational operator + (const Rational& r1, const Rational&...
4
by: Niels Dekker (no reply address) | last post by:
When calling swap as follows (as recommanded in Effective C++, 3rd Edition, by Scott Meyers), what swap is chosen to be called? using std::swap; swap(a, b); Suppose there is a global ::swap...
7
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2>...
11
by: plenty900 | last post by:
I was looking over someone's C++ code today and despite having written perfectly readable C++ code myself, the stuff I was looking at was worse than legalese. The people who are guiding the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.