i get the compiler error \"ISO C++ forbids comparison between pointer and intege
ID: 3891053 • Letter: I
Question
i get the compiler error "ISO C++ forbids comparison between pointer and integer" line 41 below. how do I compare the pointer value to the integer 100?
#include "stdafx.h"
#include "Stock.h"
Stock::Stock() //error if used
{
}
Stock::Stock(char* Symbol, int SharesOwned, float CurrentPrice, float PurchasePrice)
{
strcpy(this->Symbol, Symbol);
this->SharesOwned = SharesOwned;
this->CurrentPrice = CurrentPrice;
this->PurchasePrice = PurchasePrice;
CheckIfBuyCandidate();
}
void Stock::CheckIfBuyCandidate(void)
{
if (CurrentPrice <= PurchasePrice)
{
if (SharesOwned < 100) /// line 41
{
IsBuyCandidate = true;
}
}
}
bool Stock::GetBuyCandidate(void)
{
return IsBuyCandidate;
}
char * Stock::GetName(void)
{
return Symbol;
}
Stock::~Stock()
{
}
Explanation / Answer
Since you have copied SharesOwned so the location this->SharesOwned better to use this->SharesOwned < 100 which is accessed through some reference to the location which is stored otherwise it will result in ambiguity.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.