c++ - Unable to remove missing ; before variable name error -
#ifndef products_h #define products_h #include "products.h" class products { protected: static int count; string name_; float cost_; public: products() // default ctor { name_ = ""; cost_ = 0.0f; count++; } products(string name , float cost) //parametorized ctor { name_ = name; cost_ = cost; count++; } products(products &p ) { name_ = p -> name_; cost_ = p -> cost_; } ~products() {} string getname() { return name_; } void setname(string name) { name_=name; } float getcost() { return cost_; } void setcost(float cost) { cost_=cost } float calctotal(products *p_products) //not made yet! { float total=0.0f; for(int = 0 ; < count; i++) { total += p_products->cost_; p_products ++; } return total; } products read() { products size,*p_products; cout << "enter number of items enter:"; cin >> size; cout << endl; p_products = new products[size]; for(int = 0 ; < size; i++) { cout << "enter name:"; cin >> p_products -> name_; cout << endl << "enter cost"; cin >> p_products -> cost_; cout << endl; p_products ++; } return p_products; } void write(products *p_products) { for(int = 0 ; < count ; i++,p_products++) { cout<<"products name:\t\t"<<p_products->name_<<endl; cout<<"products price:\t\t"<<p_products->cost_<<endl; } } }; #endif
my source code is:
#include <iostream> #include <string> #include "products.h" using namespace std; static int products::count;//declaring static variable int main() { products *p_products,temp; *p_products=temp.read(); //temp.write(); system("pause"); delete[] product; return 0; }
but getting error can not remove:
error c2146: syntax error : missing ';' before identifier 'name_'
please me out!thanks
you should include string header file in first file. looks it's complaining doesn't know string is.
you need add
#include <string>
and change type of name_ to
std::string name_;
Comments
Post a Comment