Welcome! Log In Create A New Profile

Advanced

<unresolved overloaded function type>

Posted by jneethling 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar <unresolved overloaded function type>
April 05, 2009 03:36PM
Keep getting this compiler error when trying to use an overloaded operator. Checked the syntax and it looks right. Not sure if there is anything else that I am missing. Can anyone give me an idea of what I am doing wrong?

main.cpp:66: error: no match for ‘operator<<’ in ‘writer << wcl’

partial header:
Language: C++ (QT)
#ifndef CONTACTLISTWRITER_H #define CONTACTLISTWRITER_H   #include <QString> #include <QFile> #include <QTextStream> #include <QObject> #include "ContactList.h"   /** * class ContactListWriter */   class ContactListWriter : public QObject { Q_OBJECT public: friend ContactListWriter& operator<< (ContactListWriter& writer, const ContactList& cl);

Partial cpp file:
Language: C++ (QT)
ContactListWriter& operator<< (ContactListWriter& writer, ContactList& cl) { writer.write(cl); return writer; }

The code with the error:
Language: C++ (QT)
ContactListWriter writer("somefile.txt"); ContactList wcl(); writer << wcl;

Cobus Neethling
Anonymous User
Re: <unresolved overloaded function type>
April 05, 2009 04:15PM
in your cpp file, try:

Language: C++ (QT)
ContactListWriter& operator<< (ContactListWriter& writer, const ContactList& cl) { writer.write(cl); return writer; }

maybe link will help:
http://cartan.cas.suffolk.edu/oopdocbook/opensource/operatoroverloading.html

The problem might also be a scoping one ( :: )?
avatar Re: <unresolved overloaded function type>
April 06, 2009 08:25AM
That did not help, I suspect it might be a scoping issue as well but how do you specify scope for an operator?

Will try to add an operator overload to the ContactList class. Maybe c++ expects both classes to have the operators overloaded?

Cobus Neethling
avatar Re: <unresolved overloaded function type>
April 06, 2009 10:24PM
Specifying the overloaded operator as a friend neither defines it nor declares it.

The first time you define it is inside the .cpp file. Only code utilising it within this .cpp file will know about it.

If you want to use it elsewhere, you need to declare it in a header file somewhere. Best place would be either before or after the class itself.

#ifndef CONTACTLISTWRITER_H
#define CONTACTLISTWRITER_H
 
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QObject>
#include "ContactList.h"
 
/**
  * class ContactListWriter
  */

// overloading prototype declaration
 ContactListWriter& operator<< (ContactListWriter& writer, const ContactList& cl);   // <<<<<<< THIS IS THE DECLARATION

class ContactListWriter : public QObject
{
    Q_OBJECT
public:
        friend ContactListWriter& operator<< (ContactListWriter& writer, const ContactList& cl);
avatar Re: <unresolved overloaded function type>
April 06, 2009 10:26PM
oops, sorry, above function prototype can only be declared after the class because the class hasn't been defined yet.
Anonymous User
Re: <unresolved overloaded function type>
April 08, 2009 03:13PM
so did you figure out the solution? It would be nice to have feedback so that the next person who has that trouble can build from it.
avatar Re: <unresolved overloaded function type>
April 08, 2009 03:54PM
Tried last night but didn't succeed. Unfortunately we are working against a deadline and I'm not getting much time for assignments...

Cobus Neethling
avatar Re: <unresolved overloaded function type>
April 09, 2009 02:26PM
I am having exactly the same problem. I have tried a few things, but none of them has worked. I plan to work on it over the easter weekend and I will let yuo know if I find anything.
avatar Re: <unresolved overloaded function type>
April 11, 2009 09:07PM
I found my mistake - I created my ContactList as a pointer which won't work (comes from code cut and paste from a previous question to get the assignment finished). I see yours is created correctly, so not sure what else can be wrong. My ContactListWriter is identical to yours.
avatar Re: <unresolved overloaded function type>
April 28, 2009 11:06PM
Found 'one' of my problems, the write method parameter should match that of the operaor parameter:
Language: C++ (QT)
ContactListWriter& operator<< (ContactListWriter& writer, const ContactList& cl)

Language: C++ (QT)
bool ContactListWriter::write (const ContactList& contactList )

Notice the types, both have const ContactList&.

I am down to getting the list object and writing it to file.
The writing works if I comment out the offending code.

Thank you Microsoft for dumbing me down with Visual Studio! I cannot live without it's marvelous features and sensible error messages.

Cobus Neethling
Re: <unresolved overloaded function type>
May 01, 2009 09:29PM
I had the same issue with my reader (error: no match for ‘operator>>’ in ‘reader >> list’)
Fixed it by adding & in front of list:
Language: C++ (QT)
. . ContactList list; ContactListReader reader("reader.txt"); //read contacts from the file reader >> &list; . .
avatar Re: <unresolved overloaded function type>
May 02, 2009 08:30AM
@AnitaMaartens

Does your operator overload look like:

Language: C++ (QT)
ContactListReader &operator>>(ContactListReader &reader, const ContactList *list);

If it does, you could have just changed the list parameter from a pointer to a reference to save you from having to pass the memory address with the &
Re: <unresolved overloaded function type>
May 07, 2009 04:27PM
Hi Guys

I need an advice. Which is more difficult between COS311-4 and COS321-6? Which one do you guys feel is more understandable and easier to learn.
Re: COS311-4 and COS321-6
May 07, 2009 04:29PM
Hi Guys

I need an advice. Which is more difficult between COS311-4 and COS321-6? Which one do you guys feel is more understandable and easier to learn.
Anonymous User
Re: <unresolved overloaded function type>
May 07, 2009 04:34PM
take 321. It's a piece of cake. No programming.
Re: <unresolved overloaded function type>
May 08, 2009 01:05PM
Do you agree Cobus? 321 is easier than 311?
Re: <unresolved overloaded function type>
May 08, 2009 01:06PM
Appreciate the response Rick
Re: <unresolved overloaded function type>
May 08, 2009 03:01PM
Remember to check specifications for your stream:
For example both COS321-6 and COS311-4 is compulsory for the Scientific Computing and Decision Modelling and Computing stream
avatar Re: <unresolved overloaded function type>
May 11, 2009 10:00AM
I did 321 a few years ago and enjoyed it a lot. I would say it is...

Cobus Neethling
Anonymous User
Re: <unresolved overloaded function type>
May 14, 2009 10:37AM
umm Meshack I think you will have to consider your strengths/weakness that is programming/ computer architectural. For 321 being a piece of cake ...umm I doubt it tried all assignments last year for 321 with all my effort and got around 50% on average.

Also consider your experience at the moment if you are in programming already I am sure you can tackle 311, and if in archetural then 321 will be better .

Lastly you can consider your intentions after the degree , as for myself have no experience in practical programing at all except theoretically on paper gained through my studies so have decided to take 311 as it is more practical and hopefully I can be able to penetrate programing market. So faced with a challenge of 'try try try and try again till it works'

But all in all I think 321 is less challenging than 311, if you happen to choose 321 I think just try to hammer it in your head then I am sure you will be guaranteed a pass. .
Anonymous User
Re: <unresolved overloaded function type>
May 14, 2009 11:05AM
Abby, I also had no programming experience before this degree. Two years ago, a friend suggested I learn Java. I downloaded the programmer cert book and started from there. Since java is free and purely OO, this has done my programming skills a world of good. I devoted some months after the exams purely to learning Java. It paid huge dividends. One will never learn programming from Unisa only. Unisa teaches theory.
avatar Re: <unresolved overloaded function type>
May 14, 2009 11:15AM
Programming is a practical subject. It's not about a language, that's the easy part. The hard part is about looking at a problem, sifting out the 'must have's from the 'nice to have's and then disecting it till you get design and an algorithm. Only once you've got that right can you start translating the design into code.

For the stuff we do here, it's quick to get from the design stage into the code stage, most of the time you can design in your head. Take a look at assignment 3 (if you haven't received it by post yet, it's been uploaded into the Osprey downloads directory). That should give you a better idea of what programming is all about.
Anonymous User
Re: <unresolved overloaded function type>
May 14, 2009 11:47AM
Yes Rick I agree with you I downloaded java cert book and covered almost everything and should be able to write once I get some chance. Though only a few are discouraging me to take programing route as an option and consider testing.

What I was saying is Meshack should consider what his intentions are in doing certain modules other than whats easy and not, and when deciding intentions considering strengths/weakness helps.
Re: <unresolved overloaded function type>
May 14, 2009 03:57PM
Can anybody post a link of where I can get dat book or e-mail it to me pllllzzzz! manqebt@unisa.ac.za thanks in advance.
Re: COS311-4 and COS321-6
September 07, 2011 09:27PM
Hi Guys

Can you help me with some old tutorial letters you used for these subjects? Would like to look at different explanations and examples before i write the exams.

sedeya@gmail.com 0795801661

Thanks in advance.
Sorry, only registered users may post in this forum.

Click here to login