| | |
error: no match for ‘operator<<’ in ‘std::cout
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Solved Threads: 0
hello
I'm new to c++ and I'm writing a program for a college project.
I'm getting an error I don't understand, if someone can help me with it I'll be thankful
Oh, and by the way, the functions names are in French, hope this wont be a problem.
Here is my code :
faisceau.h:
and faisceau.cpp:
I'm getting this error line :
I'm new to c++ and I'm writing a program for a college project.
I'm getting an error I don't understand, if someone can help me with it I'll be thankful
Oh, and by the way, the functions names are in French, hope this wont be a problem.
Here is my code :
faisceau.h:
C++ Syntax (Toggle Plain Text)
#ifndef FAISCEAU_H #define FAISCEAU_H #include <vector> #include <iostream> #include "photon.h" class photon; class faisceau { public: void initialise(long long tps); faisceau copie(); void affichefaisceau(); private: std::vector<photon> tab_photon; }; #endif
and faisceau.cpp:
C++ Syntax (Toggle Plain Text)
#ifndef FAISCEAU_CPP #define FAISCEAU_CPP #include <vector> #include <iostream> #include "faisceau.h" #include "photon.h" void faisceau::initialise(long long tps) { photon photon_lu(tps,0); tab_photon.push_back(photon_lu); } void faisceau::affichefaisceau() { std::vector<photon>::iterator iter; for(iter=((*this).tab_photon).begin(); iter!=((*this).tab_photon).end();iter++) { cout << *iter << "\n"; } } faisceau faisceau::copie() { return(*this); } #endif
I'm getting this error line :
C++ Syntax (Toggle Plain Text)
faisceau.cpp:20: error: no match for ‘operator<<’ in ‘std::cout << iter.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = photon*, _Container = std::vector<photon, std::allocator<photon> >]()’
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
Seems that operator << is unable to take a 'photon' as input.
You probably need to write something like:
You probably need to write something like:
C++ Syntax (Toggle Plain Text)
std::ostream & operator << (std::ostream& s, const photon & p) { // stuff the content of the photon into the stream ... // s << p.abc << etc ... return s; }
Last edited by mitrmkar; Mar 8th, 2008 at 4:06 pm.
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Solved Threads: 0
you are so right! cout cant take a photon as input, horrible mistake!I didn't add the wanted element of photon.
Changed it to But it's still giving me an error.
Here's my photon.h:
Changed it to
C++ Syntax (Toggle Plain Text)
cout << *iter.ponderation << "\n";
C++ Syntax (Toggle Plain Text)
faisceau.cpp:20: error: ‘class __gnu_cxx::__normal_iterator<photon*, std::vector<photon, std::allocator<photon> > >’ has no member named ‘ponderation’
Here's my photon.h:
C++ Syntax (Toggle Plain Text)
#ifndef PHOTON_H #define PHOTON_H using namespace std; class photon { friend class faisceau; public: photon(long long tps,int pond); private: long long tps_arrive; int ponderation; }; #endif
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
Try rather ..
cout << (*iter).ponderation << "\n";
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Solved Threads: 0
I already did,
this way it gives this error :
maybe I should give you photon.cpp
#ifndef PHOTON_CPP
#define PHOTON_CPP
#include "photon.h"
photon::photon(long long tps, int pond)
{
tps_arrive=tps;
ponderation=pond;
}
#endif
this way it gives this error :
C++ Syntax (Toggle Plain Text)
/usr/lib/gcc/x86_64-linux-gnu/4.1.3/../../../../lib/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' /tmp/cczolmYC.o: In function `faisceau::initialise(long long)': faisceau.cpp:(.text+0x126): undefined reference to `photon::photon(long long, int)' collect2: ld returned 1 exit status
maybe I should give you photon.cpp
#ifndef PHOTON_CPP
#define PHOTON_CPP
#include "photon.h"
photon::photon(long long tps, int pond)
{
tps_arrive=tps;
ponderation=pond;
}
#endif
Last edited by adnanius; Mar 8th, 2008 at 4:35 pm.
•
•
Join Date: Mar 2008
Posts: 16
Reputation:
Solved Threads: 0
It did compile some time ago, but now I changed a lot of things in it.
Deleting the definition of the member function :
doesn't change anything.
And even the undeclaration of the friend class
So I think the original problem is now solved .
I'll try to figure this out.
And I'll post if I never get it right!
Thanks ! It's been a pleasure getting fast and accurate answers
Deleting the definition of the member function :
C++ Syntax (Toggle Plain Text)
void faisceau::affichefaisceau() { std::vector<photon>::iterator iter; for(iter=((*this).tab_photon).begin(); iter!=((*this).tab_photon).end();iter++) { cout << (*iter).ponderation << "\n"; } }
doesn't change anything.
And even the undeclaration of the friend class
So I think the original problem is now solved .
I'll try to figure this out.
And I'll post if I never get it right!
Thanks ! It's been a pleasure getting fast and accurate answers
Last edited by adnanius; Mar 8th, 2008 at 5:04 pm.
![]() |
Similar Threads
- How do I flush the input stream? (C++)
- binary search problem (C++)
- linked list errors (C++)
- Conversion Constructor and overloaded operator= help (C++)
- Overloaded Functions C++ (C++)
- binary tree class (C++)
- struct array and enum problems (C++)
Other Threads in the C++ Forum
- Previous Thread: unable to return values from function in c++
- Next Thread: Searching word for word
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





