BrainTrance
BrainTrance

Reputation: 89

Get entry text from wxTextCtrl in C++

I have this piece of code:

void stoiximanFrame::OnButton1Click(wxCommandEvent& event)
{
    cout<< TextCtrl1.GetValue() <<endl;

}

I just want to get the text from TextCtrl1 and I get this error:

stoiximanFrame::TextCtrl1’, which is of pointer type ‘wxTextCtrl*’ (maybe you meant to use ‘->’ ?)

I'm new to C++ so I've never used pointers before. I've read the basics of pointers but still I couldn't figure out how to solve the problem above.

In addition, I would appreciate any good documentation about how and when to use pointers.

Thanks.

Upvotes: 0

Views: 492

Answers (1)

Detonar
Detonar

Reputation: 1429

TextCtrl1 seems to be a pointer to an object of class wxTextCtrl(also wxTextCtrl*). By using the arrow operator -> you access the public members of the object the pointer is pointing to. It is a shortcut for using dereferencation(*) and member access(.).

This means TextCtrl1->GetValue() is equivalent to (*TextCtrl1).GetValue()

So just do what your compiler says and write

cout << TextCtrl1->GetValue() << endl;

to solve your problem.

If you are new to C++ i recommend you to read about pointers. For example here because that's one of the major differences to other languages.

Upvotes: 1

Related Questions