Visual C++ build error due to circular includes -
i have 2 classes use each other members.. class one:
#ifndef property_h #define property_h #include "individualproperty.h" #include "structurizer.h" #include "p_owner.h" #include <windows.h> class p_owner; class p_property { private: p_owner _owner; string ownername; string propertyaddress; string taxid; string postalcode; bool owes_taxes; double propertytaxval; double solidwastetaxval; public: p_owner getowner() { return _owner; } void setowner(p_owner a) { _owner = a; } string getpropertyaddress() { return propertyaddress; } void setpropertyaddress(string a) { propertyaddress = a; } void settaxid(string a) { taxid = a; } string gettaxid() { return taxid; } void setpostalcode(string a) { postalcode = a; } string getpostalcode() { return postalcode; } void settaxes(bool a) { owes_taxes = a; } bool gettaxes() { return owes_taxes; } void setpropertytaxval(double a) { propertytaxval = a; } double getpropertytaxval() { return propertytaxval; } void setsolidwastetaxval(double a) { solidwastetaxval = a; } double getsolidwastetaxval() { return solidwastetaxval; } p_property(string _taxid) { taxid = _taxid; } }; #endif
and class two:
#ifndef owner_h #define owner_h #include "individualproperty.h" //#include <vector> #include "property.h" class p_property; class p_owner { private: string ownername; string mailingaddress; string mailingstate; vector<p_property> ownedproperties; int numproperties; public: string getownername() { return ownername; } void setownername(string a) { ownername = a; } string getmailingaddress() { return mailingaddress; } void setmailingaddress(string a) { mailingaddress = a; } string getmailingstate() { return mailingstate; } void setmailingstate(string a) { mailingstate = a; } p_property getpropertyatindex(int a) { return ownedproperties.at(a); } void addproperty(p_property a) { ownedproperties.push_back(a); numproperties++; } int getnumproperties() { return numproperties; } p_owner(string _name, string _addy, string _state) { setownername(_name); setmailingaddress(_addy); setmailingstate(_state); numproperties = 0; } p_owner() { setownername("null"); numproperties = 0; } }; #endif
upon building error: error image
which odd because solution built fine yesterday! have insight on source of issue?
don't include property.h
in owner.h
. forward declare p_property
(as do). move method bodies refer p_property
or members owner's header owner's cpp file. that'll break dependencies.
i think have add constructor/destructor decls decl of p_owner
, provide bodies (even if empty) in owner.cpp
well.
the goal not force field of vector<p_property>
instantiate std::vector<p_property>
methods until you're compiling body of p_owner
. compiler generated constructor/destructor cause vector instantiated header.
it's not clear really want! having p_property
directly contain p_owner
, , p_owner
contain vector of directly contained p_property
s - you're not getting graph structure want! want p_property
have pointer p_owner
. possibly want p_owner
have vector of pointers to p_property
s. previous paragraphs answer question asked, can determine if right question.
Comments
Post a Comment