wxIcon Contructor Doubt 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
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

wxIcon Contructor Doubt

Post by Nick »

Thus declaring after bool OnInit() { WORK

Code: Select all

wxIcon MyIcon("./Database/FrmIcon.png", wxBITMAP_TYPE_PNG);
FrmContacts->SetIcon(MyIcon);
But I need to declare before that, in private. NO WORK

Code: Select all

class MyProgram: public wxApp {
private:
   wxIcon MyIcon("./Database/FrmIcon.png", wxBITMAP_TYPE_PNG);

Code: Select all

Contacts.cpp:27:18: error: expected identifier before string constant
   27 |    wxIcon MyIcon("./Database/FrmIcon.png", wxBITMAP_TYPE_PNG);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~
Contacts.cpp:27:18: error: expected ‘,’ or ‘...’ before string constant
How do I declare this correctly?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxIcon Contructor Doubt

Post by ONEEYEMAN »

Hi,
Please learn basic C++ prior to coding with such extensive toolkit as wxWidgets.

Thank you.
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: wxIcon Contructor Doubt

Post by Nick »

ONEEYEMAN wrote: Sun May 24, 2020 12:43 am Hi,
Please learn basic C++ prior to coding with such extensive toolkit as wxWidgets.
Thank you.
But I'm doing it! I am studying, creating examples to understand and learn. I just can't afford a course or a teacher to help me, or to clear my doubts.
One learns by studying the theory, but one learns even more by practicing what one has read in the theory, doing, every day.

If people who know more can help, it makes it easier, because studying alone, with an Internet that many codes are wrong, are obsolete, the path is much more difficult. Books are not usually practical. They are a great source of information to consult, for those who know, but for those who don't they are mostly incomplete.

It is not difficult for a person who is in college to learn programming, buy many different books that deal with the subject, pay a private teacher to clear their doubts.

Try to do it without those resources! Only with the Internet as a source of research. It's not that simple!
The only thing I'm asking for is information! I don't want to bother anyone with questions, because I ask because I don't know!

This forum has helped me a lot by answering a lot of questions I've asked, and with what I've learned I'm teaching people who speak my language and who don't understand English at all like I do.

Even with your answer, I think I understood that the problem is about C++ and not wxWidgets, that helps too!
So what's wrong with me asking?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxIcon Contructor Doubt

Post by ONEEYEMAN »

Hi,
What I mean is - start by learning the language.
Find soe kind of a community college which teaches a good course of C++ and finish it. Or maybe not so good course. Anyway - you should have a good understanding of the language itself, before you even think of doing any wxWidgets work.

I'm sure community colleges in your area can accept a financial hardships students or you can pay with some Federal tuition program.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxIcon Contructor Doubt

Post by doublemax »

Code: Select all

private:
   wxIcon MyIcon("./Database/FrmIcon.png", wxBITMAP_TYPE_PNG);
You just can't initialize member variables that way. But even if it worked, you shouldn't do it anyway.
But I need to declare before that, in private.
Why? I can't think of any scenario where your old version (Initialization in OnInit) is not sufficient. wxApp::OnInit() is the main entry point for any wxWidgets application and any kind of initialization usually happens there.

Offtopic: There is definitely no need to take (especially paid) courses or similar in order to use wxWidgets, you can find everything you need to know online. I'm 100% self-taught.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxIcon Contructor Doubt

Post by ONEEYEMAN »

doublemax,
I'm talking about C++ course.
Of course wxWidgets can be learnt online and thru the samples. But in order to use it you should have at least a basic understanding of the language.

Thank you.
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: wxIcon Contructor Doubt

Post by Nick »

doublemax wrote: Sun May 24, 2020 6:44 pm You just can't initialize member variables that way. But even if it worked, you shouldn't do it anyway.
But I need to declare before that, in private.
Why? I can't think of any scenario where your old version (Initialization in OnInit) is not sufficient. wxApp::OnInit() is the main entry point for any wxWidgets application and any kind of initialization usually happens there.
I got to this point when I was re-organizing the code. There's no specific reason. What there was was me not understanding why it doesn't work in this place.
So much for your claim that it can't be declared that way. As for ONEEYEMAN's response, it has already helped me to understand what is wrong!
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: wxIcon Contructor Doubt

Post by Nick »

ONEEYEMAN wrote: Sun May 24, 2020 6:20 pm Hi,
What I mean is - start by learning the language.
Find soe kind of a community college which teaches a good course of C++ and finish it. Or maybe not so good course. Anyway - you should have a good understanding of the language itself, before you even think of doing any wxWidgets work.

I'm sure community colleges in your area can accept a financial hardships students or you can pay with some Federal tuition program.

Thank you.
I understood what you explained, I'm striving to understand more C++.

Maybe in big cities there are schools, but where I live there is no technical course, there is not even a computer for students. There are computer courses to use windows, excel, word. They are not even very expensive, but they did not accept my request for a programming course, they said they do not have students interested enough to create 1 class.

There are professional courses, but only in big cities, where living is much more expensive. And they are not close to catch a bus.
In order for me to move to a big city, I will still need to save money. I live in Brazil
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxIcon Contructor Doubt

Post by ONEEYEMAN »

Hi,
I understand.
What about the courses online?
I'm sure there are colleges that provides online courses...

You will just have a very hard time learning both (C++ and wxWidgets) at the same time.

Just jump on the google and do the research about C++ online courses or online colleges in Brazil.

Like I said - in order to write an application using wxWidgets you have to have at least a basic understanding of the language.
Otherwise you will end up writing very bad code or you will become very frustrated, because you will hit the compiler error every time you will try something and will spend more time on the Internet than actually writing and learning how to program (with wxWidgets).

Thank you.
Post Reply