Thread: Function call problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148

    Function call problem

    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 :
    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
    
    }
    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;
    }
    I hope there is sufficient code there to explain my problem.

    Visual Studio reports:

    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
    If anyone can help I'd really appreciate it.

    Thanks very much!
    Last edited by Swerve; 11-17-2009 at 06:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM