Page 1 of 1

Basic Doubt with Function

Posted: Sat Aug 10, 2019 7:54 pm
by Nick
Beginner's Question
I understand that my current question is also somewhat similar to previous ones, but I am asking this question because I am having difficulty understanding what is happening.

Previously I was developing an application and learning from it about wxWidgets. However, I decided to start another one from scratch by doing it differently, so the following problem started!
The Example I started from scratch, just to learn and understand, I'm using Codeblocks + wxSmith.

He automatically created 5 files because he separates everything, but that's good, because it makes it easier for me to understand:
Create_FunctionsApp.cpp
Create_FunctionsApp.h
Create_FunctionsMain.cpp
Create_FunctionsMain.h
Create_Functionsframe.wxs

Situation:
In Create_FunctionsMain.h I declared the function like this:
Below

Code: Select all

class Create_FunctionsFrame: public wxFrame {
private:
    void Function_Test();
In Create_FunctionsMain.cpp I put my function below

Code: Select all

Create_FunctionsFrame::~Create_FunctionsFrame() {
    //(*Destroy(Create_FunctionsFrame)
    //*)
}

void Create_FunctionsFrame::Function_Test() {
    wxMessageBox("Test OK!");
}

// I call my function from a Form button and it WORKS
void Create_FunctionsFrame::OnAbout(wxCommandEvent & event) {
    Function_Test();
}
PROBLEM:
But this same function, already declared I can't call it in: Create_FunctionsApp.cpp

Code: Select all

#include "Create_FunctionsMain.h" // I informed her where she is declared

bool Create_FunctionsApp::OnInit() {
   //(*AppInitialize
   bool wxsOK = true;
   wxInitAllImageHandlers();
   if (wxsOK) {
      Create_FunctionsFrame* Frame = new Create_FunctionsFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)

    Function_Test(); /// error: ‘Function_Test’ was not declared in this scope

    return wxsOK;
}
I am completely lost on why this is happening.
Can someone help me?

Re: Basic Doubt with Function

Posted: Sat Aug 10, 2019 8:05 pm
by doublemax

Code: Select all

Function_Test(); /// error: ‘Function_Test’ was not declared in this scope
Function_Test is a member function of Create_FunctionsFrame, so it needs an instance of Create_FunctionsFrame.

This would work (in the context of the previous call):

Code: Select all

Create_FunctionsFrame* Frame = new Create_FunctionsFrame(0);
Frame->Show();
Frame->Function_Test();

Re: Basic Doubt with Function

Posted: Sat Aug 10, 2019 9:10 pm
by Nick
doublemax wrote: Sat Aug 10, 2019 8:05 pm Function_Test is a member function of Create_FunctionsFrame, so it needs an instance of Create_FunctionsFrame.
I understood what you meant!
I also realized that I had to take her from private to public.
But I still don't understand the difference between private, public. If you can point me where I can study this in the manual thank you.

I also realized that I can declare it completely separate from the basic way we do in C. I will calmly analyze which form I will need to use.

Thanks! :D

Re: Basic Doubt with Function

Posted: Sat Aug 10, 2019 9:35 pm
by doublemax
But I still don't understand the difference between private, public. If you can point me where I can study this in the manual thank you.
You won't find this in the wxWidgets manual, this is basic C++ stuff.

https://www.geeksforgeeks.org/access-modifiers-in-c/

Re: Basic Doubt with Function

Posted: Sat Aug 10, 2019 9:43 pm
by Nick
doublemax wrote: Sat Aug 10, 2019 9:35 pm
But I still don't understand the difference between private, public. If you can point me where I can study this in the manual thank you.
You won't find this in the wxWidgets manual, this is basic C++ stuff.

https://www.geeksforgeeks.org/access-modifiers-in-c/
Thank you very much! :D