c++ - incomplete type is not allowed while trying to create an array of pointers -


i created 2 classes, branch , account , want branch class have array of account pointers, fail it. says "incomplete type not allowed". wrong code?

#include <string> #include "account.h"  using namespace std;        class branch{      /*--------------------public variables--------------*/     public:         branch(int id, string name);         branch(branch &br);         ~branch();         account* ownedaccounts[];    // error @ line         string getname();         int getid();         int numberofbranches;     /*--------------------public variables--------------*/      /*--------------------private variables--------------*/     private:         int branchid;         string branchname;     /*--------------------private variables--------------*/     }; 

although can create array of pointers forward-declared classes, cannot create array unknown size. if want create array @ runtime, make pointer pointer (which of course allowed):

account **ownedaccounts; ... // later on, in constructor ownedaccounts = new account*[numownedaccounts]; ... // later on, in destructor delete[] ownedaccounts; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -