Programming :: C++ Operator Overloading Within Already Overloaded Operator
Apr 16, 2011
I'm having a bit of an issue using overloaded operators in an already overloaded operator. In my following code, I have overloaded the && operator to compare two Course objects. The operator in turn goes to a function which calls other overloaded operators to compare private object variables of that object to compare them.
I have a binary value which I receive from a controller. Say this binary value is 42. Just plain hex 42. If you would look at that byte in a debugger you would see 42.Now this value hold 8 bits each indicating a high or a low output. So 0x42 = 01000010b. Which means bits 1 and 6 are '1'.When I would want to find out which bits are set and which are not in a language like C, I simply do:
Code:
mask = 0x80; if (binval & mask) {...} etc..
However I am programming in TCL, and I try to do:
Code:
set mask 0x80 if { [expr ($binval & $mask) > 0] } {...} etc...
this fails. At the moment the expr is executed, $binval is evaluated and substituted so the expression I am evaluating is
Code:
set mask 0x80 if { [expr ('B' & '0x80') > 0] } {...} etc...
Eventually I got it working by converting the $binval into a '0x42' string value, like this:
Code:
binary scan $binval c byte set byte [format "0x%0x" $byte] set mask 0x80 if { [expr ($byte & $mask) > 0] } {...} etc...[
Then the expression yields what I want. But this seems so stupid and clumsy. Isn't there a better way where I can compare two binary values without conversions?
I have a simple program from book C++ cookbook, page 291, 8.3, Using Constructors and Destructors to manage resources (or RAII), but it can not get compiled in my g++
------------------------------------------------------------------------------------------------ // Example 8-3. Using constructors and destructors #include <iostream> #include <string> using namespace std;
I'm very new at Bash scripting and have a bone head issue that I'm trying (and failing) to resolve. I cannot get this one IF statement to work, it seems the comparison operator does not think the resulting number from the $b*$c+$b operation is an integer even though it is a number. Below is a small proof of concept script with the bit I'm having trouble with.
Is there a way to achieve the following with the square bracket operator?I have a class:
Code: Select allclass A { public: void SetValue(int index, Item* B); private: int m_iCount; ItemCollection Item_Collection;
[code]....
The probelm is that I am not just blindly assigning whatever given on the right hand side to the returned value from operator [], I need to verify it's not NULL, and it is not already there in the Item_Collection, and I also need to increase the count.
I know it is wrong to use the "==" operator to compare the equality of two floating point numbers. Logically it would seem that if the "==" operator is not usable for floating point comparison, then the "<=" operator would also not be usable. Is this true? The lack of google search results on this topic made me think that it must be true. If that is true, then is it true that the only way to compare floats with <= or >= is with something like the code below? Code: bool smaller_than_or_equal(float a, float b) {
if ( fabs(a-b) < EPSILON){return true;} else if (a < b) {return true;} else {return false;}
} I think this is a general question, but if specifics are necessary, I am using the C++ language to code at the moment.
I am trying to learn C++.I implemented a simple archive program, and I am in a situation in which the user is prompted by a menu to make a choice.So I have some cout instruction to illustrate the possible choices and then
int choice; cin>>choice;
and everything works fine.I introduced this code in a "while" loop that checks wether the choice made by the user is valid or not:
bool check=true; int choice; while(check) { cin>>choice; if(the choice is valid) {...;check=false} else cout<<"please make an other choice" }
What is happening is that if by mistake the user introduces a character in place of a number, the loop repeats indefinitely because the program, when it get to the "cin" instruction, does not pauses to wait for a new input.
Can one of you point me towards a comprehensive print function tutorial in perl? I was under the impression that everything within quotes will get interpolated - but I am running into exceptions where it is not desirable to run some varaibles under quotes.
I've been reading and googling, etc. I've seen some things, but not a definite explanation of this. What is the appropriate way to mimic a C ternary operator using Python? Isn't there an exact proper way to do it? Any difference for using lambda functions? I'm sorry, but I've been searching and it's ambiguous to me how this should be handled. I would appreciate a person's help on this. I came up with this link, but I'm wondering if I'm missing something.[URL]...
So, is that it? In Dive Into Python, it's using the and-or trick. Well, if the above post is the full explanation,
which definitly is not the same number. I guess somewhere in the convertion from double to char* ("<<") something is not right and what can i do to save these double numbers in an accurate manner in a file?
does the assignment operator copy all the members also for structures containing STL objects strings,vectors,vectors of vectors...)? I did try it on my platform,and it works that way (copying all the fields),but i was wondering if it is a standard behavior or not.
My compiler won't find <new>. Since it's such a basic function, I'm a bit confused. Is <new> supposed to be in a file of its own? Where do I find it? And if it turns out to be missing on my computer, where can I find a <new> one? Or do you see anything else that I do wrong?
After some trying out, it seems I can't find stuff like iostream or any other basic stuff either. The compiler is prolly looking for them at the wrong place. Does anyone know how I change or add paths for the compiler to look in when using the "<>" operator?
I have been spending several days getting wxwidgets to work in code::blocks ide on several different platforms. Now I am down to one instance that I can't figure out. I have wxwidgets working in Fedora 13 x64, but cannot get it to work in a Fedora 13 x32 version. Actually, wxwidgets seem to be installed OK, but I run into compiler errors when I try to compile the default wxhello project. I get quite a few messages, in different header files, of this type:
/usr/include/assert.h:39:42: error: missing binary operator before token "("#if defined __cplusplus && __GNUC_PREREQ (2,95) From my friend Google this would seem to be caused by an older version of boost (before 1.37) - see http://bugs.xmms2.xmms.se/view.php?id=2215 ("It is an issue with old versions of boost and gcc4.4 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36453 It is fixed in boost 1.37")
I did a yum info command on both systems for every relevant package I could think of, including gcc(v4.4.4), gcc-c++(4.4.4), libgcc(4.4.4), libstdc++(4.4.4), boost(1.41.0), wxGTK(2.8.11), wxBase(2.8.11). Both systems are fully updated and have the same versions, with the only difference being 32 vs 64 bit. The same headers compile with no errors on the x64 system, but not x32. I have been able to find no other reason for this error than older versions of the preprocessor, yet that is apparently not the case here).
I am using "if" to force a word under the condition that the first letter of that word must be a letter of the alphabet, regardless of capitalization, using the " "" != "" " syntax.
Like so:
Code: if [[ "$interface" != "WHAT DO I PUT HERE?" ]] ; then echo "Invalid input" exit 1 fi
i make this script to become a service ( i test it from bash, and my script work good), my problem is when i telnet to my local host (127.0.0.1) via a personal port like 5555 telnet give this error: ")syntax error: invalid arithmetic operator (error token is ", i know this error is for echo $(($A+$B)) and i know that telnet can not calculate $A+$B and the error is for this
recently my server become a little slow and lazy, so I started a small investigation what's going on and found out, that there is some problem with network.All processes which uses network are able to use 99% of CPU time when they got any requests. First time i thought it's only a bad configured Apache but after some research I found even FTP or SSH does it if they have to do something more (for example getting data to another server using rsync).So far I wasn't able to find a cause of this. No new software installed, only updated every few days. I have another server which have the same config, same software, same hardware and is updated in same days. But this one works without any problem. I think it's probably hardware (LAN) leaving me to it's creator. Is there some way how can I test if it's really LAN or just something bad happened to the system?
Also there is another issue - maximum speed dropped down to 20-30kB/s for both download or upload.It's Debian Lenny 2.6.22-6 if you need to know.
Iam handling mail server in redhat.MTA using is qmail.since last 1 month it get overload and get hang...since in morning its time for user to loging into mail through web interface.though suddenly login in to mail it get overload and server got hang.we need to restart the server...did not get time to kill https also some time MP port work to save us...still didnot get command to overcome the over load in server...
After upgrading to 11.04 I find that if I launch ubuntuone my machine immediately slows to a crawl and there is intense hard drive activity.This persists for hours. Only solution so far is to close ubuntuone and remove it from list of startup applications. I have made no changes to the files marked for ubuntuone syncing, and everything worked fine in 10.10.
My mom's Ubuntu machine has been rather strange the last day or so. It takes a while to turn on, delaying apparently at loading "powernowd".
GDM seems to load fine, but then logging in to Gnome takes a long time. The panels ususally crash, as well as the desktop, but eventually everything loads again.
Most programs take a long time to load; also, "sudo" takes a long time to request a password, but after that the "sudoed" command runs normally.
Gksudo never seems to show up, so I can only access programs like "Software Sources" via terminal (e.g. sudo program).
Strangely, Gnome System Monitor says the processor and memory are not completly full.
Does anyone know what this is? Are there any commands I can run to diagnose it?