Hi there,
Having difficulty with how to construct a function.
I'm storing pointers to my objects in a vector.
In the function I'm trying to pass a reference as I've learned that this is more efficient.
But since I'm storing pointers and not the actual objects I'm confused on how create the function.
I've prepared some code as an example of where I'm at:
base.h :
main.cpp :Code:using namespace std;
#include <string>
class Base
{
public:
Base(string mainname);
private:
protected:
string m_Name;
};
Base::Base(string mainname)
{
m_Name = mainname;
}
void adddoublequotes(Base& obj)//PROBLEM FUNCTION
{
Base::m_Name = '\"' + Base::m_Name + '\"';//adds double quotes to the datamember
}
I hope there is sufficient code there to explain my problem.Code:#include <iostream>
#include <string>
#include <vector>
#include "base.h"
using namespace std;
int main ()
{
vector<Base *>vectorname;
string mainname;
cout << "Enter the name " << endl;
getline (cin, mainname);
Base *ptr = new Base(mainname);
adddoublequotes(&ptr);//PROBLEM FUNCTION
vectorname.push_back( ptr );
system("pause");
return 0;
}
Visual Studio reports:
If anyone can help I'd really appreciate it.Quote:
error C2597: illegal reference to non-static member 'Base::m_Name'
error C3867: 'Base::m_Name': function call missing argument list; use '&Base::m_Name' to create a pointer to member
error C2568: '+' : unable to resolve function overload
Thanks very much!