Basic Doubt with Function Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Basic Doubt with Function

Post by Nick » Sat Aug 10, 2019 7:54 pm

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?

User avatar
doublemax
Moderator
Moderator
Posts: 14093
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Basic Doubt with Function

Post by doublemax » Sat Aug 10, 2019 8:05 pm

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();
Use the source, Luke!

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Basic Doubt with Function

Post by Nick » Sat Aug 10, 2019 9:10 pm

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

User avatar
doublemax
Moderator
Moderator
Posts: 14093
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Basic Doubt with Function

Post by doublemax » 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/
Use the source, Luke!

Nick
Knows some wx things
Knows some wx things
Posts: 37
Joined: Thu Apr 11, 2019 12:50 am

Re: Basic Doubt with Function

Post by Nick » Sat Aug 10, 2019 9:43 pm

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

Post Reply