c++ - define class as a function returning a reference -


i trying compile old source code person in lab. , cannot understand idea of following trick. why wants access clog2factory class trough reference given glogfactory()? , how can compile , link code below?

the whole code big, made short example. keep friend , virtual present in original code.
test.h:

class clog2;  class clog2factory {     friend class clog2; public:     clog2factory() {}     virtual int init() = 0; };  clog2factory&   glogfactory();  class clog2 { public:     clog2() : glogfactory().init()         { } }; 

test.cpp:

#include "test.h"  int main(int argc, char *argv[]) {     clog2 log;      return 0; } 

i following error:

test.h: in constructor ‘clog2::clog2()’: test.h:50:15: error: class ‘clog2’ not have field named ‘glogfactory’      clog2() : glogfactory().init()                ^  test.h:50:28: error: expected ‘{’ before ‘.’ token          clog2() : glogfactory().init() 

in fact, compile original code (perhaps missing in test example). couldn't link it. error linking of original code following(file test.h changed log2.h now):

log2.h:254: undefined reference `glogfactory()' 

your code missing original : a member (which type returned init() method) initialized initialization list, :

class clog2 { public:     clog2() : x(glogfactory().init())         { }      int x; }; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -