#ifndef COMPARATOR_H
#define COMPARATOR_H
#include "View.h"
class Comparator{
bool operator <(const View::Election::Candidate *& lhs, const View::Election::Candidate *& rhs){
return...
Type: Posts; User: Zosden
#ifndef COMPARATOR_H
#define COMPARATOR_H
#include "View.h"
class Comparator{
bool operator <(const View::Election::Candidate *& lhs, const View::Election::Candidate *& rhs){
return...
what would I pass a new Comparator
That still doesn't fix my original problem.
Yes I know everything works. I'm not a brand new to programming, and I've tested my code thoroughly. I just wanted to know how to sort a vector of pointers. The assignment is to have a vector of...
#ifndef COMPARATOR_H
#define COMPARATOR_H
#include "View.h"
class Comparator{
bool operator () (const View::Election::Candidate*& lhs , const View::Election::Candidate*& rhs){
return...
Those are the only pointers that I have to have for the assignment. Would having the class that just has the operator< work with the pointers.
which pointer messes it up. I can change it.
The compiler gives me this final error
bool operator<(const View::Election::Candidate*& lhs , const View::Election::Candidate*& rhs){
return *lhs->myTotalNumberOfVotes <...
Where would I overload the operator< at. Outside or inside the class, and If so how does it know to use that operator overload.
What would I place in the third parameter exactly or what pointer could I get rid of to make it easier.
Would something like this work.
std::sort(myElections->at(i)->myCandidates->begin(), myElections->at(i)->myCandidates->end(), Election::Candidate::operator ());
Where would I put that in. It won't compile when I do this.
std::sort(*(*myElections->at(i)->myCandidates->begin()), *(*myElections->at(i)->myCandidates->end()));
This is for a class, in which I'm suppose to learn c++. I'm trying to do that I understand nobody would use pointers like this. I used them like this in order to get use to using pointers. By the way...
I think that did the trick. Thanks man. Sorry for being short with you I'm just used to people who say something like you did in the beginning and then offer no help cause I'm not doing it their way....
ok thanks I forgot to add the pointers to that. I probably should take a break from the homework. How do I do the sort part. This is what I have.
...
They aren't wrong and I know how to use them, and they do point to something. I'm not an idiot. I just wanted to know how to sort the vector in c++. Could you show me an example. you don't have to...
This is what I have so far what am I doing wrong.
std::sort(myElections->at(i)->myCandidates->begin(), myElections->at(i)->myCandidates->end(), Election::Candidate::operator ());
for this...
It's a project for school I just wanted to get used to pointers. I'm new to c++ learned java last year. I just made everything a pointer so I could work with them. How would I do what you said.
I have a data structure that looks like this.
struct Election{
struct Candidate{
vector<int*>* myPrecincts;
string* myName;
int* myTotalNumberOfVotes;
};...
Wait here is the problem how do I do this right
ifstream ifstr(myInputFile.c_str());
if(!ifstr)
{
cerr << "Cannot open: " << myConversionTableFile << "." << endl;
exit(ERROR); ...
It gives me an
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check
Aborted
when I run it and it is a pointer to that vector
How do you traverse through double vectors.
for(int l = 0; l < myWordsInLetter->size(); l++)
{
for(int m = 0; m < myWordsInLetter->at(l).size(); m++)
{
cout <<...
Ignore ME sorry I figured it out.
Thanks the temp struct idea worked.
Hey I'm pretty new to C++ but have quite a bit of experience in Java. I have a project to make a Morse code translator. I have a struct that holds a letter and its morse code equivalent. Then I have...