passing a pointer to a object.

Hi,

I'm trying to pass the object storyWordManager into the constructor function of object madLib. Than use a pointer to the storyWordManager object to get information from the storyWordManager object.

Thanks



19 I:\Assignment7PointersAndClasses\main.cpp

no matching function for call to `MadLib::MadLib(StoryWordManager*)'

note I:\Assignment7PointersAndClasses\MadLib.h:21

candidates are: MadLib::MadLib(const MadLib&)

// main.cpp
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include "StoryWordManager.h"
#include "MadLib.h"


using namespace std;


int main(int argc, char *argv[])

{

StoryWordManager storyWordManager;
MadLib madlib(&storyWordManager);

system("PAUSE");
return EXIT_SUCCESS;
}


// MadLib.h

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>



#ifndef MadLib_H_
#define MadLib_H_




using namespace std;

class MadLib

{

public:

MadLib(string* const storyWordManagerPtr); // constructor prototype



};




#endif
// MadLib.cpp
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include "StoryWordManager.h"
#include "MadLib.h"


using namespace std;


// MadLib Methods

MadLib::MadLib(string* const storyWordManagerPtr) // constructor definition

{


cout << "\nHere's your story:\n";
cout << "The famous explorer ";
cout << *storyWordManagerPtr->m_Name();
cout << " had nearly given up a life-long quest to find\n";
cout << "The Lost City of ";
cout << *storyWordManagerPtr->m_Noun;
cout << " when one day, the ";
cout << *storyWordManagerPtr->m_Noun;
cout << " found the explorer.\n";
cout << "Surrounded by ";
cout << *storyWordManagerPtr->m_Number;
cout << " " << *storyWordManagerPtr->m_Noun;
cout << ", a tear came to ";
cout << *storyWordManagerPtr->m_Name << "'s ";
cout << *storyWordManagerPtr->m_BodyPart << ".\n";
cout << "After all this time, the quest was finally over. ";
cout << "And then, the ";
cout << *storyWordManagerPtr->m_Noun << "\n";
cout << "promptly devoured ";
cout << *storyWordManagerPtr->m_Name << ". ";
cout << "The moral of the story? Be careful what you ";
cout << *storyWordManagerPtr->m_Verb;
cout << " for.\n";
}

Now your constructor requires string*. You need StoryWordManager* instead.
thanks hamsterman.

But now when I use the pointer storyWordManagerPtr to try and get data out of the storyWordManager object I get another comp error.

26 G:\Assignment7PointersAndClasses\MadLib.cpp no match for 'operator*' in '*((StoryWordManager*)storyWordManagerPtr)->StoryWordManager::m_Noun'

31 G:\Assignment7PointersAndClasses\MadLib.cpp invalid type argument of `unary *'
Topic archived. No new replies allowed.