473,804 Members | 3,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why does my complier complain there is an overloaded function?

Why the following code let my compiler complain an overloaded function
Init()?

// code begin
template<class T> class BicircularList
{
template<class T> class Iterator;
template<class T> class ChainNode
{
friend Iterator<T>;
// ...
};

// ...
public:
template<class T> class Iterator
{
public:
T* Init(const BicircularList< T>& list);
T* Next();
private:
ChainNode<T> *m_pHead;
ChainNode<T> *m_pCur;
};

// ...

}

template<class T>
T* BicircularList< T>::Iterator<T> ::Init(const BicircularList< T>& list)
{
m_pHead = const_cast<Chai nNode<T> *> (&list.m_tNode) ;
m_pCur = m_pHead->m_pNext;

return (m_pCur!=m_pHea d ? &m_pCur->m_tData : 0);
}
// end of code

Here is the error message:
error C2244: 'BicircularList <T>::Iterator<T >::Init' : unable to resolve
function overload

Who can help me? Thanks!

Best regards.
Roy



Jul 19 '05 #1
4 3206
Thank Rob at first!

But here is another question: why does the following code work correctly?

// code begin
template<class T> class SparseMatrix
{
template<class T> class ElemNode
{
friend SparseMatrix<T> ;
public:
bool operator ==(const ElemNode<T>& nod) const;
bool operator !=(const ElemNode<T>& nod) const;

private:
int m_nCol;
T m_tVal;
};

template<class T> class HeadNode
{
friend SparseMatrix<T> ;
public:
bool operator ==(const HeadNode<T>& nod) const;
bool operator !=(const HeadNode<T>& nod) const;

private:
int m_nRow;
LinkedList<Elem Node<T> > m_tCol;
};

public:
SparseMatrix(in t row = 0, int col = 0);
SparseMatrix(co nst SparseMatrix<T> & sm);
~SparseMatrix() ;
// ...

private:
const int cm_nRow;
const int cm_nCol;
LinkedList<Head Node<T> > m_tRow;
};

template<class T>
inline bool SparseMatrix<T> ::ElemNode<T>:: operator ==(const ElemNode<T>&
nod) const
{
return (m_tVal == nod.m_tVal);
}

template<class T>
inline bool SparseMatrix<T> ::ElemNode<T>:: operator !=(const ElemNode<T>&
nod) const
{
return !(*this == nod);
}
// end of code


Jul 19 '05 #2
Roy Yao wrote in news:bh******** ***@mail.cn99.c om:
Thank Rob at first!

But here is another question: why does the following code work
correctly?
AFAICT It doesen't, after commenting out LinkedList< .. etc (you
supplied no declaration for this), I got:

cl /W4 /Za /Zc:forScope,wch ar_t /nologo /GR /Zi /TP /EHs test.cpp
test.cpp
test.cpp:49: error C2244: 'SparseMatrix<T >::ElemNode<T>: :operator`=='' :
unable to match function definition to an existing declaration
test.cpp:12: see declaration of
'SparseMatrix<T >::ElemNode<T>: :operator`=='' definition
'bool SparseMatrix<T> ::ElemNode<T>:: operator ==(const
SparseMatrix<T> ::ElemNode<T> &) const' existing declarations
'bool SparseMatrix<T> ::ElemNode<T>:: operator ==(const
SparseMatrix<T> ::ElemNode<T> &) const'
test.cpp:56: error C2244: 'SparseMatrix<T >::ElemNode<T>: :operator`!='' :
unable to match function definition to an existing declaration
test.cpp:13: see declaration of
'SparseMatrix<T >::ElemNode<T>: :operator`!='' definition
'bool SparseMatrix<T> ::ElemNode<T>:: operator !=(const
SparseMatrix<T> ::ElemNode<T> &) const' existing declarations
'bool SparseMatrix<T> ::ElemNode<T>:: operator !=(const
SparseMatrix<T> ::ElemNode<T> &) const'
cl (above) is VisualC 7.1 BTW.
Maybe you have a non-conforming compiler. Note all the option's
I had to give cl above to get it compile in a c++ standard
conforming way.

Any new code that you write should be tested with as many
standard conforming (or as near as possible) compilers that
you can get your hands on.

// code begin
template<class T> class SparseMatrix
{
template<class T> class ElemNode
Try changing this to:

template<class X> class ElemNode
{
You're missing the class again.
friend SparseMatrix<T> ;
friend class SparseMatrix<T> ;

Note that now we are in SparseMatrix<T> ::ElemNode< X >
and T is still available as a typename.
public:
bool operator ==(const ElemNode<T>& nod) const;
bool operator !=(const ElemNode<T>& nod) const;
Replace with:

bool operator ==(const ElemNode< X >& nod) const;
bool operator !=(const ElemNode< X >& nod) const;
Though:

bool operator ==(const ElemNode & nod) const;
bool operator !=(const ElemNode & nod) const;

Should do.

private:
int m_nCol;
T m_tVal;
};

Do the same as above, but maybe use Y instead of X, it doesn't
matter but it will be less confusing.
template<class T> class HeadNode
{
friend SparseMatrix<T> ;
public:
bool operator ==(const HeadNode<T>& nod) const;
bool operator !=(const HeadNode<T>& nod) const;

private:
int m_nRow;
//LinkedList<Elem Node<T> > m_tCol;
};

public:
SparseMatrix(in t row = 0, int col = 0);
SparseMatrix(co nst SparseMatrix<T> & sm);
~SparseMatrix() ;
// ...

private:
const int cm_nRow;
const int cm_nCol;
//LinkedList<Head Node<T> > m_tRow;
};

template<class T>

template < typename T > template < typename X > inline bool SparseMatrix<T> ::ElemNode< X >::operator ==(const ElemNode
& nod) const
{
return (m_tVal == nod.m_tVal);
}


Note the double template above.

[snip]

I'm hopping the above will demonstrate member templates, well
at least the syntax.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3
Hello Rob,

Sorry to distrub you again.

But does your solution induce that class "Iterator" can not be instantiated
when instantiating class "BicircularList "?

Now I got this message(BTW: my compiler is VC++ 6):
unresolved external symbol "public: int * __thiscall
BicircularList< int>::Iterator: :Next(void)"
(?Next@Iterator @?$BicircularLi st@H@@QAEPAHXZ)

Here is my unabridged class definition conforming your advise:
// code begin
template<class T> class BicircularList
{
public:
class Iterator;

private:
class ChainNode
{
friend class BicircularList< T>; // BTW: Is the keyword class really
necessary?
friend class Iterator;
private:
T m_tData;
ChainNode *m_pNext;
ChainNode *m_pPrev;
};

public:
class Iterator
{
public:
T* Init(const BicircularList< T>& list);
T* Next();
private:
ChainNode *m_pHead;
ChainNode *m_pCur;
};

friend class Iterator;
public:
BicircularList( );
~BicircularList ();
// ... methods omitted

private:
ChainNode m_tNode;
};
// end of code

Best Regards
Roy Yao
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:<Xn******* *************** ************@19 5.129.110.130>. ..
Roy Yao wrote in news:bh******** ***@mail.cn99.c om:
Why the following code let my compiler complain an overloaded function
Init()?

// code begin

template<class T> class BicircularList
{
// no template <class T>
class Iterator;
// no template <class T> again
class ChainNode
{
// class is required here
friend class Iterator;
// ...
};

// ...
public:
// no template <class T>

class Iterator
{
public:
T* Init(const BicircularList< T>& list);
T* Next();
private:
// removed a <T>
ChainNode *m_pHead;
ChainNode *m_pCur;
};

// ...

}; // don't forget this!
// removed a <T> after Iterator
template<class T>
T* BicircularList< T>::Iterator::I nit(const BicircularList< T>& list)
{
m_pHead = const_cast<Chai nNode<T> *> (&list.m_tNode) ;
m_pCur = m_pHead->m_pNext;

return (m_pCur!=m_pHea d ? &m_pCur->m_tData : 0);
}
Here is the error message:
error C2244: 'BicircularList <T>::Iterator<T >::Init' : unable to resolve
function overload


HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/


Jul 19 '05 #4
Now I see. Thanks agin.

"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** ***********@195 .129.110.201...
Roy Yao wrote in news:bh******** ***@mail.cn99.c om:
Now I got this message(BTW: my compiler is VC++ 6):


This will at some point be a problem, VC++ 6.0 has very poor
template support.

If upgrading is an option and you can suffer a command line
compiler then I'd suggest you download the .NET Framework SDK
it includes a version of 7.1. Its about 100M + download.

Also there is a gcc windows port MinGW http://www.mingw.org/
a ~10M download.
unresolved external symbol "public: int * __thiscall
BicircularList< int>::Iterator: :Next(void)"
(?Next@Iterator @?$BicircularLi st@H@@QAEPAHXZ)


I didn't see a declaration of:

template < class T >
T * BicircularList< T >::Iterator::Ne xt()
{
// whatever ...
}

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

70
8919
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
3
4446
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*> and use stl find string xyz;
44
2442
by: bahadir.balban | last post by:
Hi, What's the best way to implement an overloaded function in C? For instance if you want to have generic print function for various structures, my implementation would be with a case statement: void print_structs(void * struct_argument, enum struct_type stype) { switch(stype) { case STRUCT_TYPE_1:
5
2754
by: Seven Kast USA | last post by:
Hi pelase explain me complier design of c and i need a small example complier design all phases in c programming . by KAST
3
1395
by: thinktwice | last post by:
my project contains tens of files, it compiles well . now i need to add several class implementation files to the project which are similar with the classes already exist in the project, so i add new files and copy the code from the exsited files(sure need some modification). but the compiler complains 'classxxx" undeclared identifier.
2
7379
by: B. Williams | last post by:
I have an assignment for school to Overload the operators << and >and I have written the code, but I have a problem with the insertion string function. I can't get it to recognize the second of number that are input so it selects the values from the default constructor. Can someone assist me with the insertion function. The code is below. // Definition of class Complex #ifndef COMPLEX1_H
9
8182
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type); mmFree(&local_Head,(char *)mem); CPRMemory::SetMemoryHeadAs(local_Head,head_type); } ///////////////////// void* operator new(size_t sz, int head_Type) {
2
3892
by: desktop | last post by:
If a function should work with different types you normally overload it: void myfun(int a){ // do int stuff } void myfun(std::string str){ // do string stuff }
2
2118
by: subramanian100in | last post by:
overloaded operator=() -------------------------------- overloaded assignment operator should be a non-static MEMBER function of a class. This ensures that the first operand is an lvalue. If the overloaded assignment operator function is allowed to be a non- member function then we may be able to write the following: Suppose we have a class Test for which operator+() is defined, suppose we have
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.