how to get the function in class in c++?

Discussion in 'Mac Programming' started by chidambaram, Apr 8, 2008.

  1. macrumors member

    Joined:
    Mar 9, 2008
    #1
    hi all,

    I am working in a carbon c++ application using XCode in MAC machine.

    I have a class name MainWindow.

    I created a object as

    MainWindow *mainwindow = new MainWindow(2);

    MainWindow class has the function GetEditFieldData()

    When i call that function as

    mainwindow.GetEditFieldData()

    it shows the error as

    request for member 'GetEditFieldData' in 'mainwindow', which is of non-class type 'MainWindow'

    how can i solve this problem?

    Thanks in advance and urgent plz....
     
  2. m85
    macrumors newbie

    Joined:
    Apr 8, 2008
    #2
    Try mainwindow->GetEditFieldData(). This syntax is required for pointers and is shorthand for (*mainwindow).GetEditFieldData().

    Example:
    Code:
    #include <iostream>
    #include <string>
    
    class Person
    {
    	std::string _name;
    	int _age;
    	
    public:
    	Person(const std::string& name, int age) : _name(name), _age(age)
    	{
    	}
    	
    	~Person(void)
    	{
    	}
    	
    	const std::string& name(void) const
    	{
    		return _name;
    	}
    	
    	void setName(const std::string& name)
    	{
    		_name = name;
    	}
    	
    	const int& age(void) const
    	{
    		return _age;
    	}
    	
    	void setAge(int age)
    	{
    		_age = age;
    	}
    };
    
    int main (int argc, char* argv[])
    {
    	Person jobs("Steve Jobs", 53);
    	Person* woz = new Person("Steve Wozniak", 57);
    	
    	std::cout << "Steve Jobs is " << jobs.age() << " years old.\n";
    	std::cout << "Steve Wozniak is " << woz->age() << " years old.\n";
    	
    	delete woz;
    	
        return 0;
    }
    
    You can find out more here: http://www.cplusplus.com/doc/tutorial/classes.html
     
  3. thread starter macrumors member

    Joined:
    Mar 9, 2008

Share This Page