|
|
Hi
How to change associativity of operators in C++,
e.g.
if we have
int a = 15;
int b = 5;
int c = a---b;
then compiler interpret this expression as
int c = (a--) - b;
what I want, is like int c = a -(--b);
is there any way to achieve this.
Please suggest me.
Thanks & Regards
|
|
|
|
|
Use proper parenthesis in your code.
|
|
|
|
|
I don't think so.
Because the compiler doesn't know your minds. All automatic parsing is defined by rules.
Like mathematics, if you calculate 5+5*6 you should begin with 5*6 and then + 5
if you specifie it (5+5)*6 you start with adding 5+5 then the *6
It's the same in programmation.
|
|
|
|
|
Hi
thanks for your replies
Is there any prgma option to do this
please suggest me
Thans & regards
|
|
|
|
|
rajeevktripathi wrote: Is there any prgma option to do this
I didn't found any.
|
|
|
|
|
NishantB++ wrote: I didn't found any.
of course you didn't, 'cause there aren't any !
this feature is a fundamental of the language itself !!!
|
|
|
|
|
rajeevktripathi wrote: Is there any prgma option to do this
No. There is no need for that.
You write the parenthesis in your code where you need them.
When in doubt, add a pair of parenthesis. Extra pairs of parenthesis won't do any harm.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: Extra pairs of parenthesis won't do any harm
no need. one pair is largely sufficient, because it can be countered with simple spaces...
|
|
|
|
|
rajeevktripathi wrote: How to change associativity of operators in C++,
changing associativity is like changing the meaning of things (so, changing the language itself), so, no way at all.
moreover, if associativity exists like it is, there are reasons over the problem you can have with it.
rajeevktripathi wrote: then compiler interpret this expression as
int c = (a--) - b;
what I want, is like int c = a -(--b);
then, why don't you just use spaces (or at least, parenthises like someone said) ?
write c = a - --b; and everything will be good.
|
|
|
|
|
rajeevktripathi wrote: is there any way to achieve this.
Why make things harder than necessary:
int a = 15;
int b = 5;
a--;
--b;
int c = a-b;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Suppose I have two classes:
class A{
public:
A();
virtual ~A();
};
class B : virtual public A{
public:
B();
~B();
};
and I now do:
A * pA = new B();
dynamic_cast <B *> (pA);
Is there any problem. My question is actually: does the virtual inheritance affect the dynamic_cast
Thanks in advance.
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
there's no pb AFAIK. polymorphism is fully known by the compiler, and the dynamic_cast should do the job.
|
|
|
|
|
Thanks for clarifying it for me. I did test it in Visual Studio and found not problem either
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
I want to use DirectShow's interface IMediaDet to retrieve codec info from media files.
I only want to check the audio codec is AAC and video codec is MPEG-4.
How to resolve such task?
Thanks.
GOOD LUCK
|
|
|
|
|
Does the step-by-step info in the DirectShow SDK help?
IMediaDet Interface[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
But,I am sorry,I have read such document in SDK.
Now,I can read much infomation from the file,such as,media streams,duration,and so on.
In advanture,I also want to check its media codec,I want to check the audio is AAC and the video is MPEG-4.
Happy Mid-auturmn Day.
|
|
|
|
|
Hai all,
I am very glad to join to this site....
I am new to User interface development....
I would like to know some information regarding c++ UI
If any one know this,please help me?
Thanks and regards,
Rajasekharreddy.B
raja
|
|
|
|
|
raja.geek wrote: I would like to know some information regarding c++ UI
If any one know this,please help me?
Such as?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
this is too vague.
you must ask specific question is you want people to help you.
if you want to start programming user interfaces, then start by learning with a book, try the sammples...
and if some don't work like you expected, then ask here...
|
|
|
|
|
I suggest going to check out these three frameworks.
1) WPF (using C++/CLI)
2) MFC (using native C++)
3) Trolltech QT (using native C++)
Once you know what they are and a basic principle of how they work, you can start programming rich UI's for your wonderful C++ programs.
|
|
|
|
|
hi,
I have six functions in my MFC application which internally call the function AddNew() to add a new row in the database. And then Update() and Requery() after finishing with one row.
Could this cause a problem when more than one function calls AddNew() at the same time? Same with Update() and Requery()?
function1()<br />
{<br />
ptr->AddNew();<br />
ptr->Update();<br />
ptr->Requery();<br />
}
What issues could arise because of this kind of a structure??
|
|
|
|
|
How is it possible for two or more of your functions to be called at the same time?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually im using six Socket Class. So each one has its own OnReceive() function which in turn call their respective 'parsing function' (So there are 6 parsing functions). Each of these parsing functions calls its own 'AddNew()' method (total of 6 AddNew() calls)to add a row in the database.
|
|
|
|
|
That's fine. As long as there's only one thread, there's no concurrency
issues. If your 6 sockets are all creaed on the same thread then all the
OnReceive() calls occur on one thread (I'm assuming you're using CSocket
or CAsyncSocket).
If the sockets were all on separate threads, and all shared the same "ptr"
variable, then you'd have problems.
If the sockets were all on separate threads, and all had separate connections to the
DB, then the concurrency rules for the DB would apply.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|