c++ - Confused by class constructor and initializer list, suspicious of circular dependency -


i want pass referenced instance of class through class's constructor. cannot so, because stuck in syntax error. tried several hours, though learned many things (such circular dependency or forward declaration), practically cannot solve issue. have files:

project.h (the constructor of project class passed reference instance of buffer class)

project.cpp

buffer.h

buffer.cpp

the above 4 files active in problem (my guess).

here project.h content:

#include<string> #include<regex> #include<iostream> #include<vector> #include "buffer.h"  using namespace boost::filesystem;  #ifndef project_h #define project_h  class project(buffer & buffer_param) : bufferobj(buffer_param) {      buffer& bufferobj;  public:      filer& filer;      std::string project_directory;     void createlist(std::vector<std::string> list_title); };  #endif 

here project.cpp content:

#include<string> #include<regex> #include<iostream> #include<vector> #include<boost\filesystem.hpp>  #include "project.h"   using namespace boost::filesystem;   void project::createlist(std::vector<std::string> list_title) {     //this->filer.createfile(); } 

buffer.h

    #include<string>     #include<map>       #ifndef buffer_h     #define buffer_h      class buffer     {         std::map<std::string, std::string> storage_str;          void setvaluestring(std::string key, std::string value);         std::string getvaluestring(std::string key);     };      #endif 

buffer.cpp

#include<string> #include<map> #include "buffer.h"   void buffer::setvaluestring(std::string key, std::string value) {     this->storage_str[key] = value; } 

problem:

without passing buffer project constructor, works perfectly, start passing instance of it, errors thrown:

all errors of project.h file:

error c2143: syntax error : missing ')' before '&' error c2143: syntax error : missing ';' before '&' error c2079: 'buffer' uses undefined class 'project' error c2059: syntax error : ')' error c4430: missing type specifier - int assumed. note: c++ not support default-int error c2530: 'buffer_param' : references must initialized error c2143: syntax error : missing ';' before ':' error c2448: 'bufferobj' : function-style initializer appears function definition 

error of project.cpp file:

error c2027: use of undefined type 'project'       see declaration of 'project' 

to elaborate on deviantfan's comment, instead of this

class project(buffer & buffer_param) : bufferobj(buffer_param) {   ... 

there should this:

class project { public:   project(buffer & buffer_param) : bufferobj(buffer_param)   {   }  private:   ... 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -