Thanks chaps!
Here is what I've done, is it as it should be?
base.h :
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& ptr)//PROBLEM FUNCTION
{
//Base->m_Name = '\"' + Base->m_Name + '\"';//adds double quotes to the datamember
cout << "Test cout" << endl;
}
main.cpp :
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;
}
Is this correct?
The compilers telling you that the class "Base" has no static member/field called "m_Name"--which is correct. In your code above, you probably want to refer to the given instance's field "m_Name". So you probably want to do something like this "obj->m_Name" instead of trying to access a field that belongs to the class that doesnt exist "Base::m_Name".
Another problem is that "adddoublequotes" does not have access to the protected variable "m_Name", even if you fixed the previous error.
Thanks for posting this, subject to the code above being correct, yes, that is the problem I'm having now.
This is what I've come up with:
base.h :
Code:
using namespace std;
#include <string>
class Base
{
public:
Base(string mainname);
void adddoublequotes(Base& ptr);
private:
protected:
string m_Name;
};
Base::Base(string mainname)
{
m_Name = mainname;
}
void Base::adddoublequotes(Base& ptr)
{
m_Name = '\"' + m_Name + '\"'; //adds double quotes to the datamember
}
main.cpp :
Code:
#include <iostream>
#include <string>
#include <vector>
#include "diary.h"
using namespace std;
int main ()
{
vector<Base *>vectorname;
string mainname;
cout << "Enter the name " << endl;
getline (cin, mainname);
Base *ptr = new Base(mainname);
ptr->adddoublequotes(*ptr); //PROBLEM FUNCTION
vectorname.push_back( ptr );
system("pause");
return 0;
}
I would most welcome any feedback on what I've done. I seems to work OK, but I may of screwed up somewhere.
Appreciate the help!