|
Thank you for your very elaborate answers.
|
|
|
|
|
I've done cooperative multitaskers on a number of platforms (not ARM, but I don't think it should present any unusual problems) and found them to be extremely handy in cases where the set of tasks is fixed. Even if a task would spend most of its time in a loop:
while(!x_ready)
task_spin();
the cost to switch to the task, check x_ready, and then switch to the next task may be less than the cost of a more complicated scheduler trying to decide if it should switch to that task.
The biggest design issue with a cooperative task switcher is deciding what invariants are going to hold any time code does a task_spin(). While a preemptive multitasker would require that functions acquire locks before breaking any invariant even temporarily, and re-establish the invariant before releasing the lock, cooperative task switching doesn't require that. More significantly, it doesn't require that tasks do anything special to handle the fact that a lock isn't available. The gotcha is that if an invariant can't be upheld during some operation, and the time required to perform that operation could grow beyond the maximum amount of time one wants to go without a task_spin(), handling that situation may be complicated.
|
|
|
|
|
String Area = AreaCBox.Text;
DAL.CaseBarCode csbrt = new DAL.CaseBarCode();
System.Data.DataSet csbrs = csbrt.GetPO(Area);
foreach (DataRow dr in csbrs.Tables[0].Rows)
{
POCBox.Items.Add(dr["ProductionOrder"]);
}
Hello,
In the above the code I am calling a stored procedure(csbrt.GetPO(Area)) which retrieves two values "ProductionOrder" and "colorflag" columns. I am inserting ProductionOrder into 'POCBox' combobox.
Now my requirement is to color the text for ProductionOrder in the combobox to green if the colorflag value is 0 and color it red if the colorflag value is 1. Please help with the code. Thanks in advance.
|
|
|
|
|
What you want is called an "owner drawn" combobox.
There's a great article right here on CP that explains how to do it with all the code you need:
Implementing an OwnerDrawn ComboBox[^]
And by the way, you posted this in the C++ forum instead of the C# forum where it belongs.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
#include <iostream>
using namespace std;
template <class T>
class Num {
protected:
T val;
public:
Num(T x) { val = x;}
virtual T getval() { return val; }
};
template <class T>
class SqrNum : public Num<T> {
public:
SqrNum(T x) : Num<T>(x) {}
T getval() { return (val * val); }
};
int main(){
Num<int> *bp, numInt_ob(2);
SqrNum<int> *dp, sqrInt_ob(3);
Num<double> numDouble_ob(3.3);
bp = dynamic_cast<Num<int>*> (&sqrInt_ob);
if(bp) {
cout << "Cast from sqrNum<int>* to Num<int>* OK.\n"
<< "Value is " << bp->getval() << endl;
}
else
cout << "Error !\n\n";
dp = dynamic_cast<SqrNum<int>> (&numInt_ob);
if(dp)
cout << "Error !\n";
else {
cout << "Cast from Num<int>* to SqrNum<int>* not OK.\n"
<< "Can't cast a pointer to a base object into\n"
<< "a pointer to a derived object\n\n";
}
bp = dynamic_cast<Num<int>*> (&numDouble_ob);
if(bp)
cout << "Error" << endl;
else {
cout << "Can't cast from Num<double>* to Num<int>*.\n"
<< "These are 2 different types.\n\n";
}
return 0;
}
in the code above i m getting error that
Quote: error: 'val' was not declared in this scope
T getval() { return (val val); }
^~~
but
Quote: class SqrNum : public Num<t>
according to this the protected value in the base class should just work fine as protected value in the derived class, but it isn't ?
How do i solve this problem ?
EDIT :
below is the working code:
#include <iostream>
using namespace std;
template <class T>
class Num {
protected:
T val;
public:
Num(T x) { val = x;}
virtual T getval() { return val; }
};
template <class T>
class SqrNum : public Num<T> {
public:
SqrNum(T x) : Num<T>(x) {}
T getval() { return (Num<T>::val * Num<T>::val); }
};
int main(){
Num<int> *bp, numInt_ob(2);
SqrNum<int> *dp, sqrInt_ob(3);
Num<double> numDouble_ob(3.3);
bp = dynamic_cast<Num<int>*> (&sqrInt_ob);
if(bp) {
cout << "Cast from sqrNum<int>* to Num<int>* OK.\n"
<< "Value is " << bp->getval() << endl;
}
else
cout << "Error !\n\n";
dp = dynamic_cast<SqrNum<int>*> (&numInt_ob);
if(dp)
cout << "Error !\n";
else {
cout << "Cast from Num<int>* to SqrNum<int>* not OK.\n"
<< "Can't cast a pointer to a base object into\n"
<< "a pointer to a derived object\n\n";
}
bp = dynamic_cast<Num<int>*> (&numDouble_ob);
if(bp)
cout << "Error" << endl;
else {
cout << "Can't cast from Num<double>* to Num<int>*.\n"
<< "These are 2 different types.\n\n";
}
return 0;
}
Thank you
modified 6-Jun-18 0:49am.
|
|
|
|
|
dp = dynamic_cast<SqrNum<int>*> (&numInt_ob);
Needs an '*' after <int>.
Code now runs successfully.
|
|
|
|
|
i added * after SqrNum<int> but it is still giving that error .
|
|
|
|
|
Did not give that error in the original code that I compiled.
|
|
|
|
|
Quote: template <class t="">
class SqrNum : public Num<t> {
public:
SqrNum(T x) : Num<t>(x) {}
T getval() { return (val * val); }
};
Should be
template <class T>
class SqrNum : public Num<T> {
public:
SqrNum(T x) : Num<T>(x) {}
T getval() { return (Num<T>::val * Num<T>::val); }
};
|
|
|
|
|
Quote: return (Num<t>::val * Num<t>::val);
but i have already inherited all the members of the base class to the derived class, then why i need to use scope resolution operator to point where to look for val ?
|
|
|
|
|
|
|
|
How can i access the Device manager part of the Windows API?
I want to beable to show what certain devices are connected in a project in a custom application.
ill be Writing it in C++
Any ideas?
|
|
|
|
|
This may be a good starting point.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi everyone!
I've been, for the past days, searching for the smallest executable for Windows. The reason is that I want to start a small macro for a game (basically just presses a key and maybe draw some pixels on screen), and I'd like it to be tiny, just for the sake of it. I'll not use NASM, however; I intend to use Ollydbg or another such tool to directly "code" in the executable itself (sort of like a challenge).
I searched the web for the smallest executable, and it appears to be 97 bytes large. I couldn't find it for download, but I don't think it would run in any version of Windows (I want it to run from XP up (XP,7,8,10)). I found one called "hh2 golden.exe" (~400 bytes), which apparently runs from XP up, but it prints "Hello World!" in the screen (I'd like one that did nothing).
Also, I couldn't assemble them (I don't know how to properly use NASM or other assembler). I'd use "hh2 golden.exe", but or other assemblerthen I had the idea to ask here if one of you guys have a better executable that I could use in this adventure.
tl;dr: I'm asking for the smallest executable capable of running from winXP up. Preferrably it does nothing, since I want to modify it and put some functionality to it (but I need it to be completely clear at the beginning)
Thanks!
|
|
|
|
|
|
How can i be good on coding to start programming?
|
|
|
|
|
Understand problem solving.
Ask questions.
Ability to think outside the box.
et al
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
You will work hardly.
You will learn hardly.
You will communicate with other programmers (in Forums, news groups, and so on) hardly.
...
Good luck!
|
|
|
|
|
Quote: How can i be good on coding to start programming? I start programming in order to be good on coding. FFY.
Experience matters.
|
|
|
|
|
Programming is more than just writing code - it's about solving problems with code. You'll need to develop analysis and troubleshooting skills in addition to straight coding skills.
Having said that, the best way to learn how to write code is to actually write code. You could start by looking at Codecademy. It's free, it's all done in the browser (so you don't have to set up a development environment on your local machine), and they cover a useful range of languages.
I haven't used it much myself, so I can't comment on the quality of the instruction. It may be good, it may be awful. Depends on what you want to learn.
|
|
|
|
|
Ability to follow instructions.
Ability to "read in-between lines" - not every programming task is spelled out in details.
There is a difference between being a "coder" which requires mastering the tool - programming language - of your choise, and being a programmer.
As already mentioned there is no substitute for experience.
Attention to details - loose the "don't sweat the small stuff attitude " fast.
And above all - start coding.
Best of luck
Cheers
Vaclav
|
|
|
|
|
you need to love it,
you need to have fun while solving problems,
you need to have patience and open mind,
you need to be regular,
you need lot's of practice and good books,
and the rest will follow.
that's what i have experienced till date.
|
|
|
|
|
I am trying to improve my error handling skills.
I am somewhat happy with "perror", but that "requires" that the preceding code can report meaningful error messages. Most of the time all I need is "success" message and nothing more specific when error occurs.
There is a "feature" in Eclipse IDE which let me "surround" selected code , try /catch is one of them.
However, being a greenhorn , I cannot decipher this error message I am getting
Exception does not name a type
I know what "does not name a type" means , but HOW do I fix it for "Exception"?
I did Ask Mrs Google and she did not help much.
The extra block in the code is there because I just "surrounded" the perror line.
Of course the actual error message is not yet there, until I fix this missing type error.
Help will be appreciated.
Cheers
Vaclav
<pre lang="c++">
// returns file descriptor
int memfd = open("/dev/mem", O_RDWR | O_SYNC);
if(memfd)
{
try {
perror("Failed open /dev/mem ");
} catch (Exception e) {
}
exit(1);
}
</pre>
|
|
|
|