I wanna make a pointer array that holds address of objects in that class so when i call scanner function it ll read pcode and search for objects has the same pcode. am i declaring array wrong? or did i misunderstand static concept? or something else ?
anyways i guess have to posting whole code
#include <string>
using namespace std;
class product{
public:
product();
product(long&,string&);
void setCode();
void getCode(long);
void static scanner();
void const printer();
static product *point[3];
static int a;
private:
string pname;
long pcode;
};/*
class PrepackedFood:public product{
public:
PrepackedFood(long&, string&,double);
private:
double uPrice;
};
class FreshFood:public product{
public:
FreshFood(long&,string&,double,double);
private:
double weight;
double pricepk;
};*/
#include "product.h"
#include <iostream>
product::product(){pcode=0;pname="unknown";
point[a]= this;
a++;}
product::product(long& c,string&n){pcode=c;pname=n;
}
//void const product::printer(){cout<<getCode()}
void product::setCode(){ cout<<"enter product name\n ";cin>>pname;
cout<<"enter product code _____\b\b\b\b\b";cout<<"\a";
cin>>pcode;cout<<endl;
cout<<pname<<endl;
cout<<pcode<<endl;
}
void product::getCode(long s){
if ((*this).pcode=s){
printer();
}
}
void product::scanner(){
long a;
cout<<"SCANNING!\a_____\b\b\b\b\b";cin>>a;
int i=0;
while(i<3){
if (point[i]->pcode==a){point[i]->printer();
break;
}
i++;
//(i==3)?cout<<"try again\n":"\a";
}
}
void const product::printer(){
cout<<pname<<endl;
cout<<pcode<<endl;
}
#include "product.h"
int main(){
product a[3];
int i=0;
while(i<3){
a[i].setCode();
i++;
}
product::scanner();
return 0;
}
i know it can be done a lot more easily i am just learning so just wanna fix scanner function. it doesn't compile
1>product.obj : error LNK2001: unresolved external symbol "public: static class product * * product::point" (?point@product@@2PAPAV1@A) 1>product.obj : error LNK2001: unresolved external symbol "public: static int product::a" (?a@product@@2HA)