2

How do I create the same struct/variables with same functions without interfering with the existing header files at the global declarations segment? The global variables segment (Main.cpp) is as listed below the header code

Take note - I'm not allowed to edit the header file to have noEntry/Explorable (Special case)

HEADER CODE

struct PathFinderResource
{
    pthread_t                       activeThreadArray       [MAX_NO_OF_THREADS];
    PathFinderParameterInfo *       activeThreadParamArray  [MAX_NO_OF_THREADS];

    VectorOfPointStructType         solutionPath;
    VectorOfPointStructType         discoveredDangerAreas;
    //VectorOfPointStructType noEntry;
    //VectorOfPointStructType explorable;
    int                             usedThreadNameIndex;
    int                             noOfDeadEndPathsFound;
    int                             noOfBarriersDiscovered;
    int                             noOfDangerAreaDiscovered;

    PathFinderResource (void)
    {
        usedThreadNameIndex         = 0;
        noOfDeadEndPathsFound       = 0;
        noOfBarriersDiscovered      = 0;
        noOfDangerAreaDiscovered    = 0;
        solutionPath                = VectorOfPointStructType ();
        discoveredDangerAreas       = VectorOfPointStructType ();
    }

    ~PathFinderResource (void)
    {
        solutionPath.clear ();
        discoveredDangerAreas.clear ();
    }
};

PathFinderResource globalPathFinderResource;

MAIN.cpp These are my various attempts to solve the following error

Assn3.cpp:311:42: error: ‘struct Assignm3::PathFinderResource’ has no member named ‘noEntry’ globalPathFinderResource.noEntry.push_back (nextPoint); ^ Assn3.cpp: In function ‘VectorOfPointStructType findAlternativePath(VectorOfPointStructType)’: Assn3.cpp:347:35: error: ‘struct Assignm3::PathFinderResource’ has no member named ‘explorable’ if (!globalPathFinderResource.explorable.empty ()) ^ Assn3.cpp:349:43: error: ‘struct Assignm3::PathFinderResource’ has no member named ‘explorable’ for (j = globalPathFinderResource.explorable.rbegin() ; j < globalPathFinderResource.explorable.rend() ; j++)

// Global Variables
const std::string filename = "mazedata.txt";

globalPathFinderResource noEntry = VectoryOfPointStructType();
globalPathFinderResource explorable = VectoryOfPointStructType();
//VectorOfPointStructType noEntry = VectorOfPointStructType ();
//VectorOfPointStructType explorable = VectorOfPointStructType ();
//globalPathFinderResource VectorOfPointStructType noEntry = VectorOfPointStructType();
//globalPathFinderResource VectorOfPointStructType explorable = VectorOfPointStructType();
Marcus Moo
  • 196
  • 1
  • 2
  • 20
  • `PathFinderResource globalPathFinderResource;` is `Variable Type & Variable name`. `globalPathFinderResource noEntry = VectoryOfPointStructType();` is what? – UKMonkey Feb 21 '18 at 12:46
  • I'm trying to create something using global variable so that i can utilize the functions below while its clocked in globalpathfinderesource e.g. globalPathFinderResource.noEntry.rbeing() etc. @UKMonkey – Marcus Moo Feb 21 '18 at 12:48
  • @UKMonkey cause its supposed to replicate the effects of the following lines in HEADER.h //VectorOfPointStructType noEntry; //VectorOfPointStructType explorable; – Marcus Moo Feb 21 '18 at 12:50
  • You can't just add functions into a class. You need to change the class definition if you want to do that – UKMonkey Feb 21 '18 at 12:52
  • Hmm not really adding functions into a class but struct PathFinderResource { pthread_t activeThreadArray [MAX_NO_OF_THREADS]; PathFinderParameterInfo * activeThreadParamArray [MAX_NO_OF_THREADS]; VectorOfPointStructType solutionPath; VectorOfPointStructType discoveredDangerAreas; //VectorOfPointStructType noEntry; //VectorOfPointStructType explorable; to duplicate the same results of VectorOfPointStructType noEntry (for example in this case) – Marcus Moo Feb 21 '18 at 12:53
  • 1
    Are you trying to create a new instance of the class `PathFinderResource`? In any case, whatever you're trying to do, your syntax is wrong, and I would suggest a visit to [this](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) page – UKMonkey Feb 21 '18 at 13:03
  • @UKMonkey hmm. creating instance would be just like that. But i want it to be of VectorOfPointStructType =============== Assnigm3::PathFinderResource noEntry; Assnigm3::PathFinderResource explorable; – Marcus Moo Feb 21 '18 at 13:13

0 Answers0