PDA

View Full Version : how to get the function in class in c++?




chidambaram
Apr 9, 2008, 01:22 AM
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....



m85
Apr 9, 2008, 02:35 AM
Try mainwindow->GetEditFieldData(). This syntax is required for pointers and is shorthand for (*mainwindow).GetEditFieldData().

Example:

#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

chidambaram
Apr 9, 2008, 04:31 AM
Thank you

its working