|
Moved this question to the proper forum "Managed C++/CLI"
Feel free to delete i cant
modified 27-Jul-22 10:29am.
|
|
|
|
|
I guess you should have posted it into the Managed C++/CLI Forum.
|
|
|
|
|
Thanks Victor for explaining i s in the wrong forum
i did for look for a managed C++ CLI forum but i totaly failed
I will moved my question to the right one now :¬)
modified 27-Jul-22 10:32am.
|
|
|
|
|
After a long time not using C++, I picked it for a pet-project...
It works perfectly, but I have the feeling I use older solutions in my code, than those are available today. My code probably is pre C++11 (do we call it ANSI?)...
I'm looking for some reference material that can help me to learn the new and shiny things I may want to use in my code to make it faster, maintainable and readable...
“Real stupidity beats artificial intelligence every time.”
― Terry Pratchett, Hogfather
|
|
|
|
|
I use this for reference: cppreference.com[^]. But it may depend on how skilled you are at the basics of C++.
|
|
|
|
|
Thank you for the link - will investigate it...
(After COBOL, I used C++ solely for like 5-6 years, than for an other 2 years occasionally... So I'm not a master, but understand it fairly...)
“Real stupidity beats artificial intelligence every time.”
― Terry Pratchett, Hogfather
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: I'm not a master Me too.
|
|
|
|
|
thanks for that link. Holy Crap, I still have a lot to learn.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
|
|
Thank You!
“Real stupidity beats artificial intelligence every time.”
― Terry Pratchett, Hogfather
|
|
|
|
|
How do you use a pointer to a function that is declared in the general scope within a class.
Do you pass the pointer as parameter to class function, save the pointer as a class member and then use the class member in a class function when needed?
void somefunction(int i);
void (*pointertosomef)(int i) = somefunction;
class SomeObject
{
void (*m_pointertosomef)(int i);
public:
void ImportPointerToF(void (*pointertosomef)(int i));
void UsePointerToF();
}
void SomeObject::ImportPointerToF(void (*pointertosomef)(int i))
{
m_pointertosomef = pointertosomef;
}
void SomeObject::UsePointerToF()
{
m_pointertosomef(30);
}
I found on the internet the basic version of declaring a pointer function
void fun(int a);
void (*fun_ptr)(int) = fun;
fun_ptr(10);
Everything else is my speculation
|
|
|
|
|
|
Does it compile, build and run without errors? The only caveat I would mention is that pointers to class methods require the method to be static.
|
|
|
|
|
ok, thanks to both of you.
Quote: Does it compile, build and run without errors
Usually I don`t try to compile wild guesses. I did things as you would do with a pointer in my post above but often in c++ things that resemble in some places don`t have a syntax that matches everywhere.
modified 16-Jul-22 10:16am.
|
|
|
|
|
Calin Cali wrote: Usually I don`t try to compile wild guesses.
Well, you should because:
1. Might take less time than waiting for an answer.
2. Compiler is never cranky or in a bad mood. At most it will issue an error message.
3. One wild guess leads to another and soon you end up with a nice brilliant idea
Mircea
|
|
|
|
|
Quote: Well, you should because:
For me it feels like trying to compile a quote from Ceaikovski or Twain.
|
|
|
|
|
Mircea is quite correct, you should always try and build small samples. Apart from anything else, the error reports help you to learn. The compiler, linker and debugger excellent tools that aid in development. Had you started in the days when we had to submit a deck of punched cards and wait 24 hours for the compiler output to tell us one character was mistyped, you would appreciate how easy things are these days.
|
|
|
|
|
It`s interesting to hear where things started. I had my first computer experience in the 80`s on a computer with keyboard and a dedicated green and white screen (the screen was displaying only two colors). My first programming experience was on a computer that you had to connect to a TV set. It was a computer with 16 colors graphics.
|
|
|
|
|
Mine was the LEO* III in the 60s, second row first three pictures at Leo Computers Society. Leo 3 photos[^]. Most input was punched paper tape, and some punched cards, no mass storage, only magnetic tape.
*The Lyons Electronic Office, initially developed between Lyons Catering and English Electric, both companies long gone.
|
|
|
|
|
Working in the field since the beginning I imagine you had a computer from every generation.
|
|
|
|
|
Not quite, I started in the transistor age, so things were getting quite sophisticated.
|
|
|
|
|
You're creating a pointer to a free function (one defined outside a class) and then storing it, and invoking it, from within an object. But it's also possible to create a pointer to class member data or a member function. See here[^]. You may need to read several articles about this to gain a good understanding, because I can't point to one that is really good on its own. Search on "C++ pointer to member" and read articles that discuss the type Class::* (a pointer to a class member) and operators .* and ->* . These make the following possible:
int Class::* pm = &Class::m; int (Class::* pf)(int) = &Class::f; Class c, *k;
c.*pm = 1; n = c.*pf(0); k->.pm = 2; n = (k->*pf)(0);
|
|
|
|
|
I'm attempting to convert a decimal to binary such as 192 to 11000000. I simply need a basic code to do this yet the code I have so far doesn't work:
void dectobin(int value, char* output)
{
int i;
output[5] = '\0';
for (i = 4; i >= 0; --i, value >>= 1)
{
output[i] = (value & 1) + '0';
}
}
Prior to this, done thorough research on decimal to binary in cI and gone through some good Articles, to have a clear understanding of the topic.
Any help would be much appreciated!
modified 23-Sep-22 12:22pm.
|
|
|
|
|
You don’t say exactly why it doesn’t work so I’ll just guess: the code works only with numbers up to 2^5=32. If you tried it with 192 it would have failed.
As a general advice, for small algorithms like that, it helps to “play the computer”: take a piece of paper and go through each step as you would be the computer. That gives you a better understanding of how the algorithm works and helps you find eventual bugs.
Mircea
|
|
|
|