Click here to Skip to main content
16,017,638 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I tried to carry compile the foowing code:
C++
string stSubjAbbreviation = q9.getStringField(0);

				vector<vector<string>> vSubClassSubjScore;
				copy_if(vClassSubjScores.begin(), vClassSubjScores.end(), back_inserter(vSubClassSubjScore),
					[stSubjAbbreviation](vector<string> &vStudentSubjScore)
					{
						return (vStudentSubjScore[1] == stSubjAbbreviation);
					});

				sort(vSubClassSubjScore.begin(), vSubClassSubjScore.end(),
					[](vector<string>& vStudentSubjScore, vector<string>& vStudentSubjScore1)
					{
						return (stoi(vStudentSubjScore[2]) < stoi(vStudentSubjScore[2]));
					});

				for (int i = 0; i < classResult.size(); i++)
				{
					int iHighest = 0;
					int iLowest = 0;
					int iAverage = 0;
					auto p = max_element(vSubClassSubjScore.begin(), vSubClassSubjScore.end(),
						[](vector<string>& vStudentSubjScore, vector<string>& vStudentSubjScore1)
						{
							return (stoi(vStudentSubjScore[2]) < stoi(vStudentSubjScore[2]));
						});
					if (p != vSubClassSubjScore.end())
					{
						int j = distance(vSubClassSubjScore.begin(), p);
						vector<string> vStudentSubjScore = vSubClassSubjScore[j];
						string stHighest = vStudentSubjScore[2];
					}

					p = min_element(vSubClassSubjScore.begin(), vSubClassSubjScore.end(),
						[](vector<string>& vStudentSubjScore, vector<string>& vStudentSubjScore1)
						{
							return (stoi(vStudentSubjScore[2]) < stoi(vStudentSubjScore[2]));
						});
					if (p != vSubClassSubjScore.end())
					{
						int j = distance(vSubClassSubjScore.begin(), p);
						vector<string> vStudentSubjScore = vSubClassSubjScore[j];
						string stLowest = vStudentSubjScore[2];
					}

					string stSurname = classResult[i].GetSurname();
					string stFirstName = classResult[i].GetFirstName();
					string stMiddleName = classResult[i].GetMiddleName();
					string stName = CreateName(stSurname, stFirstName, stMiddleName);

					string stPosition;
					p = find(vSubClassSubjScore.begin(), vSubClassSubjScore.end(),
						[stName](vector<string>& vStudentSubjScore)
						{
							return (vStudentSubjScore[0] == stName);
						});
					if (p != vSubClassSubjScore.end())
					{
						int iPosition = distance(vSubClassSubjScore.begin(), p);
						stPosition = CreatePosition(iPosition++);
					}

					int iSum = 0;
					for_each(vSubClassSubjScore.begin(), vSubClassSubjScore.end(),
						[&iSum](vector<string>& vStudentSubjScore)
						{
							iSum += stoi(vStudentSubjScore[2]);
						});
					double dAverage = (double)iSum / (double)vTuple.size();
					iAverage = Approximate(dAverage, 1);

					vector<string> vectorNew;
					vectorNew.push_back(to_string(iHighest));
					vectorNew.push_back(to_string(iLowest));
					vectorNew.push_back(to_string(iAverage));
					vectorNew.push_back(stPosition);

					auto q = find(classResult.begin(), classResult.end(),
						[stName](StudentInfo& StudInfo)
						{
							return (StudInfo.GetName() == stName);
						});

					int iPos = distance(classResult.begin(), q);
					map<string, vector<string>> mMap(map{ pair(stName, vectorNew) });
					classResult[iPos].SetSubjectPermfomance(mMap);
				}
but got the following compiation errors:
>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5740,21): error C2446: '==': no conversion from 'const _Ty' to 'std::vector<std::string,std::allocator<std::string>>'
1>        with
1>        [
1>            _Ty=LoadResultBuffer::<lambda_5>
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5740,24): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5754,36): message : see reference to function template instantiation '_InIt std::_Find_unchecked<std::vector<std::string,std::allocator<std::string>>*,_Ty>(_InIt,const _InIt,const _Ty &)' being compiled
1>        with
1>        [
1>            _InIt=std::vector<std::string,std::allocator<std::string>> *,
1>            _Ty=LoadResultBuffer::<lambda_5>
1>        ]
1>C:\Users\HP\source\repos\ResultSheets\DBaseQuery.h(7204,10): message : see reference to function template instantiation '_InIt std::find<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,LoadResultBuffer::<lambda_5>>(_InIt,const _InIt,const LoadResultBuffer::<lambda_5> &)' being compiled
1>        with
1>        [
1>            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::vector<std::string,std::allocator<std::string>>>>>,
1>            _Ty=std::vector<std::string,std::allocator<std::string>>
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5740,21): error C2446: '==': no conversion from 'const _Ty' to 'StudentInfo'
1>        with
1>        [
1>            _Ty=LoadResultBuffer::<lambda_7>
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5740,24): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5754,36): message : see reference to function template instantiation '_InIt std::_Find_unchecked<StudentInfo*,_Ty>(_InIt,const _InIt,const _Ty &)' being compiled
1>        with
1>        [
1>            _InIt=StudentInfo *,
1>            _Ty=LoadResultBuffer::<lambda_7>
1>        ]
1>C:\Users\HP\source\repos\ResultSheets\DBaseQuery.h(7231,15): message : see reference to function template instantiation '_InIt std::find<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,LoadResultBuffer::<lambda_7>>(_InIt,const _InIt,const LoadResultBuffer::<lambda_7> &)' being compiled
1>        with
1>        [
1>            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<StudentInfo>>>,
1>            _Ty=StudentInfo
1>        ]

The surprising thing is that I had had a data structure of the type:
C++
tuple<string,string,string,int> 
that got the same error message.It compained that cost_Ty could notbe converted to tuple<string,string,int> which I had used as a part of this code segment but laterchanged its structure. Why can't algorithmn handle data sructures as state above.

The strcture of studentInfo is as shown below:
C++
<pre>#include <string>

using namespace std;

class Address
{
	string m_stStreet;
	string m_stLocality;
	string m_stCity;
	string m_stState;
	string m_stCountry;
public:
	Address() = default;
	Address(const Address& obj) = default;
	Address(Address&& obj) = default;
	Address& operator = (const Address& obj) = default;
	Address& operator = (Address&& obj) = default;

	bool operator == (const Address& obj);
	bool operator != (const Address& obj);
	bool operator < (const Address& obj);
	bool operator > (const Address& obj);
	bool operator <=(const Address& obj);
	bool operator >=(const Address& obj);

	void SetStreet(string& stStreet);
	string GetStreet();

	void SetLocality(string& stLocality);
	string GetLocality();

	void SetCity(string& stCity);
	string GetCity();

	void SetState(string& stState);
	string GetState();

	void SetCountry(string& stCountry);
	string GetCountry();
};

C++
<pre>#include <string>
#include <vector>
#include "AppTypes.h"
#include "Address.h" 

using namespace std;

class SchInfo
{
	SchType m_eSchType{ SchType::ST_NA };
protected:
	string  m_stSchName;
	Address m_Addr;
	vector<string>  m_vSubjOfferred;
	string m_stLogoPath;
	int m_iTimesSchOpened;
public:
	SchInfo() = default;
	SchInfo(const  SchInfo& obj) = default;
	SchInfo(SchInfo&& obj) = default;
	SchInfo& operator = (const  SchInfo& obj) = default;
	SchInfo& operator = (SchInfo&& obj) = default;

	bool operator == (const SchInfo& obj);
	bool operator != (const SchInfo& obj);
	bool operator < (const SchInfo& obj);
	bool operator > (const SchInfo& obj);
	bool operator <= (const SchInfo& obj);
	bool operator >= (const SchInfo& obj);

	void SetSchName(string& stSchName);
	string GetSchName();

	void SetSchType(SchType& eSchType);
	SchType GetSchType();

	void SetAddress(Address& Addr);
	Address GetAddress();

	void SetSubjOfferred(vector<string>& vSubjOfferred);
	vector<string> GetSubjOfferred();

	void SetLogoPath(string& stLogoPath);
	string GetLogoPath();

	void SetTimesSchOpened(int &iTimesSchOpened);
	int GetTimesSchOpened();
};

C++
<pre>#include <string>
#include "SchInfo.h"
#include "AppTypes.h"

using namespace std;

class ArmInfo : public SchInfo
{
protected:
	string m_stArmName;
	ArmType m_eArmType{ ArmType::AT_NA };
	pair<string, string> m_pSession;
public:
	ArmInfo() = default;
	ArmInfo(const  ArmInfo& obj) = default;
	ArmInfo(ArmInfo&& obj) = default;
	ArmInfo& operator = (const  ArmInfo& obj) = default;
	ArmInfo& operator = (ArmInfo&& obj) = default;

	bool operator == (const ArmInfo& obj);
	bool operator != (const ArmInfo& obj);
	bool operator < (const ArmInfo& obj);
	bool operator > (const ArmInfo& obj);
	bool operator <= (const ArmInfo& obj);
	bool operator >= (const ArmInfo& obj);

	void SetArmName(string& stArmName);
	string GetArmName();

	void SetArmType(ArmType& eArmType);
	ArmType GetArmType();

	void SetSession(pair<string, string>& pSession);
	pair<string, string> GetSession();
};

C++
<pre>#include <string>
#include "ArmInfo.h" 

class ClassInfo : public ArmInfo
{
protected:
	string m_stClassName;
public:
	ClassInfo() = default;
	ClassInfo(const  ClassInfo& obj) = default;
	ClassInfo(ClassInfo&& obj) = default;
	ClassInfo& operator = (const  ClassInfo& obj) = default;
	ClassInfo& operator = (ClassInfo&& obj) = default;

	bool operator == (const ClassInfo& obj);
	bool operator != (const ClassInfo& obj);
	bool operator < (const ClassInfo& obj);
	bool operator > (const ClassInfo& obj);
	bool operator <= (const ClassInfo& obj);
	bool operator >= (const ClassInfo& obj);

	void SetClassName(string& stClassName);
	string GetClassName();
};
C++
<pre>#include <string>
#include <map>
#include <vector>
#include <stdexcept>
#include "SchInfo.h" 
#include "ArmInfo.h"
#include "ClassInfo.h"
#include "AppTypes.h"
#include "CreateName.h"

using namespace std;

class StudentInfo : public ClassInfo
{
	string m_stSurname;
	string m_stFirstName;
	string m_stMiddleName;
	int m_iAge{};
	StudentType m_eStudentType{ StudentType::SDT_NA };
	map<string, string> m_mCAScores;
	map<string, string> m_mExamScores;
	vector <map<string, int>> m_vSessionScores;
	map<string, vector<string>> m_mSubjectPermfomance;
	map<string, string> m_mPsychomotorSkillRating;
	map<string, string> m_mAffectiveDomainRating;
	string m_stClassTeacherComment;
	string m_stPrincipalComment;
	int m_iGPA{};
	int m_iTotalAttendance{};
	string m_stPicturePath;

	int m_iStudentTotal{};
	double m_dStudentAverage{};

	int m_iAnnualStudentTotal{};
	double m_dAnnualStudentAverage{};

	map<string, int> m_mTermCount;
	
public:
	StudentInfo() = default;
	StudentInfo(const  StudentInfo& obj) = default;
	StudentInfo(StudentInfo&& obj) = default;
	StudentInfo& operator = (const  StudentInfo& obj) = default;
	StudentInfo& operator = (StudentInfo&& obj) = default;

	bool operator == (const StudentInfo& obj);
	bool operator != (const StudentInfo& obj);
	bool operator < (const StudentInfo& obj);
	bool operator > (const StudentInfo& obj);
	bool operator <= (const StudentInfo& obj);
	bool operator >= (const StudentInfo& obj);

	void SetSurname(string& stSurname);
	string GetSurname();

	void SetFirstName(string& stFirstName);
	string GetFirstName();

	void SetMiddleName(string& stMiddleName);
	
	string GetMiddleName();

	void SetAge(int iAge);
	int GetAge();

	void SetStudentType(StudentType& eStudentType);
	StudentType GetStudentType();

	void SetCAScores(map<string, string>& mCAScores);
	map<string, string> GetCAScores();

	void SetExamScores(map<string, string>& mExamScores);
	map<string, string> GetExamScores();

	void SetSessionScores(map<string, int>& vSessionScores);
	map<string, int> GetSessionScores(int iIndex);

	map<string, vector<string>> GetSubjectPermfomance();
	void  SetSubjectPermfomance(map<string, vector<string>>& mSubjectPermfomance);

	void SetPsychomotorSkillRating(map<string, string>& mPsychomotorSkillRating);
	map<string, string> GetPsychomotorSkillRating();

	void SetAffectiveDomainRating(map<string, string>& mAffectiveDomainRating);
	map<string, string> GetAffectiveDomainRating();

	void SetClassTeacherComment(string& stClassTeacherComment);
	string GetClassTeacherComment();

	void SetPrincipalComment(string& stPrincipalComment);
	string GetPrincipalComment();

	void SetPicturePath(string& stPicturePath);
	string GetPicturePath();

	void SetTotalAttendance(int& iTotalAttendance);
	int GetTotalAttendance();

	void SetGPA(int& iGPA);
	int GetGPA();

	void SetStudentTotal(int &iStudentTotal);
	int GetStudentTotal();

	void SetStudentAverage(double &dStudentAverage);

	double GetStudentAverage();

	void SetTermCount(map<string, int> &mTermCont);
	map<string, int> GetTermCount();

	void SetAnnualStudentAverage(double& dAnnualStudentAverage);

	double GetAnnualStudentAverage();

	string GetName();
};

C++
<pre>#include <string>
#include "ArmInfo.h" 

class ClassInfo : public ArmInfo
{
protected:
	string m_stClassName;
public:
	ClassInfo() = default;
	ClassInfo(const  ClassInfo& obj) = default;
	ClassInfo(ClassInfo&& obj) = default;
	ClassInfo& operator = (const  ClassInfo& obj) = default;
	ClassInfo& operator = (ClassInfo&& obj) = default;

	bool operator == (const ClassInfo& obj);
	bool operator != (const ClassInfo& obj);
	bool operator < (const ClassInfo& obj);
	bool operator > (const ClassInfo& obj);
	bool operator <= (const ClassInfo& obj);
	bool operator >= (const ClassInfo& obj);

	void SetClassName(string& stClassName);
	string GetClassName();
};

C++
<pre>#include <string>
#include <vector>
#include <map>
#include <stdexcept>
#include "Address.h"
#include "SchInfo.h" 
#include "ArmInfo.h" 
#include "ClassInfo.h" 
#include "StudentInfo.h" 
#include "AppTypes.h" 

using namespace std;

class ClassResult
{
	vector<StudentInfo> m_vStudResult;
public:
	ClassResult() = default;
	ClassResult(const ClassResult& obj) = default;
	ClassResult(ClassResult&& obj) = default;
	ClassResult& operator = (const ClassResult& obj) = default;
	ClassResult& operator = (ClassResult&& obj) = default;

	bool operator == (const ClassResult& obj);
	bool operator != (const ClassResult& obj);
	bool operator >= (const ClassResult& obj);
	bool operator <= (const ClassResult& obj);
	bool operator < (const ClassResult& obj);
	bool operator > (const ClassResult& obj);
	
	void SetStudResult(StudentInfo &StudResult);

	StudentInfo GetStudResult(int iIndex);

	StudentInfo& operator[](int iIndex);

	int size();
	vector<StudentInfo>::iterator begin();
	vector<StudentInfo>::iterator end();

	void clear() { return m_vStudResult.clear(); }
};
The euality operator foreach class is shown below:
C++
<pre>bool Address::operator == (const Address& obj)
{
	return ((m_stStreet == obj.m_stStreet) &&
		(m_stLocality == obj.m_stLocality) &&
		(m_stCity == obj.m_stCity) &&
		(m_stState == obj.m_stState) &&
		(m_stCountry == obj.m_stCountry));
}

C++
bool SchInfo::operator == (const SchInfo& obj)
{
	return ((m_eSchType == obj.m_eSchType) &&
		(m_stSchName == obj.m_stSchName) &&
		(m_Addr == obj.m_Addr) &&
		(m_vSubjOfferred == obj.m_vSubjOfferred) &&
		(m_stLogoPath == obj.m_stLogoPath) &&
		(m_iTimesSchOpened == obj.m_iTimesSchOpened));
}

C++
<pre>bool ArmInfo::operator == (const ArmInfo& obj)
{
	return ((m_stArmName == obj.m_stArmName) &&
		(m_eArmType == obj.m_eArmType) &&
		(m_pSession == obj.m_pSession) &&
		(dynamic_cast<SchInfo&>(*this) == dynamic_cast<SchInfo&>(const_cast<ArmInfo&>(obj)))
		);
}

C++
bool ClassInfo::operator == (const ClassInfo& obj)
{
	return ((m_stArmName == obj.m_stArmName) &&
		(dynamic_cast<ArmInfo&>(*this) == dynamic_cast<ArmInfo&>(const_cast<ClassInfo&>(obj))) &&
		(dynamic_cast<SchInfo&>(*this) == dynamic_cast<SchInfo&>(const_cast<ClassInfo&>(obj)))
		);
}

C++
<pre>bool StudentInfo::operator == (const StudentInfo& obj)
{
	return ((m_stSurname == obj.m_stSurname) &&
		(m_stFirstName == obj.m_stFirstName) &&
		(m_stMiddleName == obj.m_stMiddleName) &&
		(m_iAge == obj.m_iAge) &&
		(m_eStudentType == obj.m_eStudentType) &&
		(m_mCAScores == obj.m_mCAScores) &&
		(m_mExamScores == obj.m_mExamScores) &&
		(m_vSessionScores == obj.m_vSessionScores) &&
		(m_stPicturePath == obj.m_stPicturePath) &&
		(m_iTotalAttendance == obj.m_iTotalAttendance) &&
		(m_mSubjectPermfomance == obj.m_mSubjectPermfomance) &&
		(m_mPsychomotorSkillRating == obj.m_mPsychomotorSkillRating) && 
		(m_mAffectiveDomainRating == obj.m_mAffectiveDomainRating) &&
		(m_stClassTeacherComment == obj.m_stClassTeacherComment) &&
		(m_stPrincipalComment == obj.m_stPrincipalComment) &&
		(m_iGPA == obj.m_iGPA) &&
		(m_iStudentTotal == obj.m_iStudentTotal) &&
		(m_dStudentAverage == obj.m_dStudentAverage) &&
		(m_mTermCount == obj.m_mTermCount) &&
		(m_iAnnualStudentTotal == obj.m_iAnnualStudentTotal) &&
		(m_dAnnualStudentAverage == obj.m_dAnnualStudentAverage) &&
		(dynamic_cast<ClassInfo&>(*this) == dynamic_cast<ClassInfo&>(const_cast<StudentInfo&>(obj))) &&
		(dynamic_cast<ArmInfo&>(*this) == dynamic_cast<ArmInfo&>(const_cast<StudentInfo&>(obj))) &&
		(dynamic_cast<SchInfo&>(*this) == dynamic_cast<SchInfo&>(const_cast<StudentInfo&>(obj)))
		);
}

C++
bool ClassResult::operator == (const ClassResult& obj)
{
	return (m_vStudResult == obj.m_vStudResult);
}




I removed the dynamic cast in the classes above and replaced them with actual base class data member comparison and I got the following two compiation errors. What do they mean?



1.
C++
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): error C3889: call to object of class type 'std::equal_to<void>': no matching call operator found
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xstddef(210,31): message : could be 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) noexcept(<expr>) const'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : Failed to specialize function template 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) noexcept(<expr>) const'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : With the following template arguments:
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : '_Ty1=const StudentInfo &'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : '_Ty2=const StudentInfo &'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5194,17): message : see reference to function template instantiation 'bool std::equal<_InIt1,_InIt2,std::equal_to<void>>(const _InIt1,const _InIt1,const _InIt2,_Pr)' being compiled
1>        with
1>        [
1>            _InIt1=const StudentInfo *,
1>            _InIt2=const StudentInfo *,
1>            _Pr=std::equal_to<void>
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vector(2228,21): message : see reference to function template instantiation 'bool std::equal<const StudentInfo*,const StudentInfo*>(const _InIt1,const _InIt1,const _InIt2)' being compiled
1>        with
1>        [
1>            _InIt1=const StudentInfo *,
1>            _InIt2=const StudentInfo *
1>        ]
1>C:\Users\HP\source\repos\ResultSheets\ClassResult.h(97,24): message : see reference to function template instantiation 'bool std::operator ==<StudentInfo,std::allocator<StudentInfo>>(const std::vector<StudentInfo,std::allocator<StudentInfo>> &,const std::vector<StudentInfo,std::allocator<StudentInfo>> &)' being compiled
1>UpdateStudentRecord.cpp













2.

C++
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): error C3889: call to object of class type 'std::equal_to<void>': no matching call operator found
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xstddef(210,31): message : could be 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) noexcept(<expr>) const'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : Failed to specialize function template 'unknown-type std::equal_to<void>::operator ()(_Ty1 &&,_Ty2 &&) noexcept(<expr>) const'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : With the following template arguments:
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : '_Ty1=const StudentInfo &'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5177,14): message : '_Ty2=const StudentInfo &'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\xutility(5194,17): message : see reference to function template instantiation 'bool std::equal<_InIt1,_InIt2,std::equal_to<void>>(const _InIt1,const _InIt1,const _InIt2,_Pr)' being compiled
1>        with
1>        [
1>            _InIt1=const StudentInfo *,
1>            _InIt2=const StudentInfo *,
1>            _Pr=std::equal_to<void>
1>        ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\vector(2228,21): message : see reference to function template instantiation 'bool std::equal<const StudentInfo*,const StudentInfo*>(const _InIt1,const _InIt1,const _InIt2)' being compiled
1>        with
1>        [
1>            _InIt1=const StudentInfo *,
1>            _InIt2=const StudentInfo *
1>        ]
1>C:\Users\HP\source\repos\ResultSheets\ClassResult.h(97,24): message : see reference to function template instantiation 'bool std::operator ==<StudentInfo,std::allocator<StudentInfo>>(const std::vector<StudentInfo,std::allocator<StudentInfo>> &,const std::vector<StudentInfo,std::allocator<StudentInfo>> &)' being compiled


What I have tried:

I have spent hours trying to figure otthe error. I don't thinkgoogle can help with this.
Posted
Updated 3-Dec-23 9:13am
v5
Comments
Amarnath S 3-Dec-23 1:30am    
Looks more like a linking issue. However, to really eliminate compilation errors, you should compile each of the files individually, and fix all compilation issues. Then see whether the library references are proper, to remove all linking errors.
Richard MacCutchan 4-Dec-23 5:01am    
I think your classes are overly complex. If you use standard library containers then you should not need to override all the comparison operators. Start with the first class you are trying to buidl, and remove all the superfluous code. Now see if that compiles, and if not, try to figure out why. As it stands you have far too much code posted above to make the problem clear.

It is some type mismatch on some "==" operations. The message sound like you compare the vector with an object. So comment out some vector code to find the bug.
 
Share this answer
 
The algorithms are fine, the issue is with your code, as shown by the compiler error messages. I am far from being expert in either algorithms or C++ Lamdas, but I would suspect your overrides of operator==.
 
Share this answer
 
The previous solutions are on the right track. You have this definition :
C++
vector<StudentInfo> m_vStudResult;
in ClassInfo and then you have this code :
C++
bool ClassResult::operator == (const ClassResult& obj)
{
	return (m_vStudResult == obj.m_vStudResult);
}
You can not compare vectors like that regardless of what they contain.

Items in a vector must compared item-by-item.
Something like this :
C++
bool ClassResult::operator == (const ClassResult& obj) const
{   // NOTE - the const qualifier was missing previously
    // compare sizes

    size_t size = m_vStudResult.size();
    if( size != obj.m_vStudResult.size() )
        return false;   // the sizes differ

    // compare individual items

    for( size_t n = 0; n < size; ++n )
	    if( m_vStudResult[ n ] != obj.m_vStudResult[ n ] )
            return false;   // item n does not match

    return true;       // all items match
}
My previous statement was incorrect. You actually can compare two vectors and there are a few methods that do it. While the code shown for the comparison is unnecessary, it will work and it will actually have slightly better performance than the default implementation. I know this because I have compared the two closely and they do essentially the same things but in different ways.

They key thing that was missing in the OP's implementation and one reason it will not compile is the equals operator must be const because both sides of the comparison are const and that is what the comparison implementation's predicate expects. I struggled with this for a while in my testing program and once I made it const everything compiled and ran correctly.
 
Share this answer
 
v3
Comments
k5054 3-Dec-23 13:33pm    
my 5. For having the fortitude to examine the code dump, if nothing else :)
Rick York 3-Dec-23 16:10pm    
Thanks. Actually I just happened to notice the last code snippet had the issue.
Jesus Reigns 3-Dec-23 14:52pm    
so, how does one compare vector contents. Do you mind enlightening me? I was ofthe opinion that the conidition for using a container is that the class in question must define all required operators. Is that not the case?
Rick York 3-Dec-23 16:02pm    
You have to compare item by item. I will amend the solution to illustrate this.
Richard MacCutchan 4-Dec-23 4:12am    
I am no expert on containers, but operator==,!=,<,<=,>,>=,<=>(std::vector) - cppreference.com[^] says different.

[edit]
I have just verified that the default implementation of operator==does indeed work. Which leaves OP's own override as the probable culprit.
[/edit]
The original problem with my code was that I dynamic_cast to base classes in my operator == and operator > in my classes. When my code did not work and I saw an error that was related to use of operator==. So, I added the various operators to the ClassResult class to compare vectors. This le to further errors.

So, the solution was that I remove the dynamic cast and made all private members of the base classes potected. With that one I was able to compare every data member up to the topmost base class data members in my opeator== and operator operator < functions. The error that resulte next showed that std::vetors tried to compare my classes with std::less_than an failed. So,realised that the poblem was that I defined my own operator functions for the vector class. As soon as I commente out my definition of the operator function, my code compiled successfully.

I discover also an incorrect comparison in the original code, so there is a possibility that the cause of the initial errors was the incorrect comparison and not the use of dynamic cast to the base class.


Howeve, the rule for using containers for ones one classes is that you must define any comparison operator that the containe has not defined an requires that you must define in order to store you classes in the container. Re-defining a comparison operator than a container has aleay defined will lea to complilation errors. Put succinctly: operato functions cannot be overriden. don't define them for your classes if they already exist.

Finally, it is incorrect to test container data element by element in an operator function.it is absoutely incorrect.The correct thing do is to define your own operato function and let the container take it up from there.Wheneve it need to compare you class objects, it willsimply call yuor class operator function.

The following code is perfectly legal:




C++
bool ClassResult::operator == (const ClassResult& obj)
{
	return (m_vStudResult == obj.m_vStudResult);
}



The code below will only cause your classes to incure unnneccessary overhead, so dont't use it:


C++
bool ClassResult::operator == (const ClassResult& obj)
{
    // compare sizes

    size_t size = m_vStudResult.size();
    if( size != obj.m_vStudResult.size() )
        return false;   // the sizes differ

    // compare individual items

    for( size_t n = 0; n < size; ++n )
	    if( m_vStudResult[ n ] != obj.m_vStudResult[ n ] )
            return false;   // item n does not match

    return true;       // all items match
}



EDIT:
I now believe that the original probem with my code was the use of dynamic cast for operator== and operator < because an incorrect compaison that I did (which in this case was the use of m_iGPA == m_iGPA instead of m_iGP== obj.m_iGPA) could not have led to a compiation error but to a bug.

So, the use of dynamic_cast in operator functions is inapproriate.
 
Share this answer
 
v2
Comments
0x01AA 4-Dec-23 13:56pm    
Now I think it comes up to nearly the same (ok, vector maybe handle this slightly more performant).
Read this how vector implements operator ==
operator==,!=,<,<=,>,>=,<=>(std::vector) - cppreference.com[^]
Richard MacCutchan 4-Dec-23 15:54pm    
See my commen t above to Rick York.
Jesus Reigns 5-Dec-23 17:31pm    
It is wrong to re-invent the wheel. Don't discard a winning team. If a containner already oes it well and probably better, then let it do the work. The less coe you personally write, the lesser your chances of experiencing a bug.
Richard MacCutchan 6-Dec-23 4:01am    
Very true.
Rick York 6-Dec-23 19:42pm    
"The code below will only cause your classes to incure unnneccessary overhead, so dont't use it:"

That is false. That code will NOT incur any additional overhead and will, in fact, be faster than the STL implementation. It has has half the number of increment operations, half the number of comparisons, and one less function call. The fact is, the speed difference will be very small and probably unnoticeable except for with a very large collection on a slower machine BUT there will no additional overhead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900