I'm working a personal project where I have two applications namely Server, Client. when Server is started, it continuously transmits data. When Client is opened, it is ready to consume the data and display it.
I will put both .exe files in a shared location (LAN). Therefore Sever and Client will be launched from different machines. When I searched for articles that teach how to establish communication between the two, I was offered with choices like NamedPipes, WCF, Polling etc.. I'm not sure whether they will work in a LAN based environment.Also are there any other means of establishing communication?
I have a device that have some communication protocols and it will respond and send some specific data when somebody communicates with the device. I tried to build a C code that will send those protocols to the device and then store those sending data. Now I don't understand that how to send those commands. Other things than that I can manage with the file handling programming.Is there any predefined function using which it will send some specific data or something like that??
I've coded this client/server application and it works fine becuase a client can send a message to the server, so is the server to the client and mutiple clients can be connected to the server at the same time. But my problem is that I want two client to be able to communication with each other through the server. What I don't know how to do is to relay a message in the server from one client to the other. Is there a way to do this? By the way this is a chat application i'm creating.
This has been bothering me for a while now, and I finally put together an example:
#include <iostream> #include <string> using namespace::std;
[Code]....
In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?
i am relatively new to c++, and am trying to make it so particles will gravitationally attract to the mouse pointer. i have gotten all the bugs that the compiler found, but there must be another because the program crashes the second i open it. my code could be way off, so just tell me if it is and ill do more research and learning before trying something like this again. here is the code:
I've been really busy but managed to get in enough down time to learn somewhat decent info about vectors. Anyways originally my program created a dynamic array of pointers to class objects and I came across a few problems because of this. Apparently an array of pointers is now outta of the question and I will now be switching to a vector of objects instead.
Why I want a list of objects instead of pointers this little comment should clear things up.
tiles[i]->show() dereferences tiles[i] (i.e. accesses whatever it points at) before calling the show() method.
That is undefined behaviour. Once undefined behaviour occurs, there is no recovery, and there is nothing the show() method (or any subsequently called function for that matter) can do to recover (short of invoking their own forms of undefined behaviour - compiler specific hacks, etc).
Even if the show() method initialises the object correctly, it cannot change the pointer tiles[i] which is in a different scope (within main()).
What I'm trying to do is create a vector of already intialized objects so that I can use a conditional statement of every single element to properly layer my games art resources. This should also automatically fix a mild unrelated collision dectection problem too but first thing first layering.
here's the problem. I want to delete the objects within a vector, although I'm not sure whether I should clear the vector afterwards. Is it really necessary?
Code:
for (i = 0; i < allSales.size(); i++) delete allSales[i];
well the question is how to compile objects in a subdirectory?
Code:
./bo/%.o : %.c $(CC) $(CFLAGS) <$
the command abouve will compile my objects but leave them in the same directory. However I want them in a different directory. in ./bo directory. How to achieve that ? I just realize that if i remove ./bo/ from the line it does not work..
I have an array of pointers to Mat objects (an OpenCV class used to hold info and data about an image), which I will use to store the images. The function imread reads an image and returns a Mat object loaded with the relevant data about the image.However, this gives me a nice segfault when the assignment takes place. Of course, I can swap it with the following code, but since I'm working with big images (2048x2048 and upwards), it's really inefficient:
for(unsigned int i = 0; i < MAX_IMAGES; i++) { imageName[11] = 49 + i; datacube[i] = new Mat(imread(imageName, -1)); }
Is there any way to do this elegantly and without much hassle?Again, excuse my rustiness and anything completely stupid I might have said. It's been a long time since I worked with C++. Managed to circumvent the problem by using a STD vector instead of an array. I'd still like to know the answer to this riddle...
I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.
I keep getting an undesired value in this code. I've tried several methods, but none are giving me the correct answer. The out put is always zero, when in this case it should be 10!!
Here's the object structure:
template<class T, class _b> struct quantity { private: T value; public: explicit quantity(T val): value(val) {}; T getValue() { return value; };
Why does it seem that the assignment operator is the harder operator to overload? Maybe it's just my luck, but I seem to always run into issues whenever I work with it. I hardly ever experience errors when overloading any of the other operators.
I have a question regarding how GCC relates a header file and its binary file.
main.c #include <math.h> #include <stdio.h> int main (void){ double x = sqrt (2.0); printf ("The square root of 2.0 is %f ", x); return 0; }
we can compile it by running the line: gcc main.c -lm -o main
My question is: How GCC knows where is the definition of sqrt?
First I was thinking that there was and object file with the name math.o inside libm.a (that is GCC will look for an object file with the same name as the header file), but after running the next line I think my assumption was wrong as there is not such file in libm.a.
nm libm.a | grep math.o nm: e_acos.o: no symbols nm: k_cos.o: no symbols nm: k_sin.o: no symbols
I've started programming my little program called vLibrary (program I want to make for the library in my city) and after I m done with console application I will try to implement wxWidgets.My program will be able to add new users to the system, new books and new librarians.
Now, I m confused what data types to use and how to store objects (newly created users, books etc) to my program so later on they can log in the system etc. Logic of the program is completely clear to me but I m not sure how to make array of objects and store them in memory or in a certain file, how to store password and make some kind of encryption etc.which data structure from STL should I use and how.
I'm currently trying to access a variable contained within a base object from another completely different object and I continually get error messages. I'll attempt to put up the important code since it's contained within fairly large classes. From the Base .cpp file. ObjectPosition:
This is the initialization function for the BaseObject. All objects are inheriting these variables which are Protected within the ObjectPosition class.Then they are initialized within the Pig class thus wise:
I have two classes, Parent and Child, where Parent contains a vector that is used to store instances of Child. When I create an instance of Parent, three instances of Child are also created in Parent's constructor and stored in the vector. I understand that push_back() creates a shallow copy of each Child instance and that Child's destructor is called each time the loop (inside Parent's constructor) iterates. The problem is that because Child's destructor is called each time the local variable child goes out of scope, the memory previously allocated in Child's constructor is destroyed and when Child's destructor is called again later on in the program to get rid of the copy stored in vector, the program crashes. I can fix this by overriding the default copy function or by storing pointers to objects instead of copies of objects. I don't really need to use vectors in this case since I always have three children in one parent but I'm doing this as a learning exercise and would prefer to use vectors.
I'm using the SDL library and trying to match the C++11 standards... Anyway, I thought about a vector where I store all the addresses of game instances, so I can access them anytime... I tried with this function:
Where "Instance" is the 'parent' class of various child classes like the player. So, if I have to search the existing of a thing in my game, I should check if the address references to an instance of class. How can I do this?
I am preparing for an exam, and I am being told there will be, "1 multiple-choice question about reading a piece of code about objects interacting with functions and deciding the output."
There are a few ways I can think of:
- Passing an object into a function as an argument - An object calling a function with a dot operator - Creating a new object through a Constructor and Class(Does that count?)
Are there other ways that objects interact with functions that I am not thinking of?
How do we design a container of objects all of which belong to some subclass which directly/indirectly inherits from a given parent class? Moreover, I would like to have functions that enable me to pick only objects of a certain class type from the container.
For example if the parent class is A and I have a hierarchy of classes that derive from it, we must have a container that can contain any class that exists in this hierarchy. Also, get_B() must be able to let me examine only those objects in this container that inherit (directly/indirectly) from class B (class B exists in the hierarchy rooted at A).
Preferably, we would like to avoid downcasting. Or even explicit typechecking of any sort.
I have been working on an assignment where I have to add three objects of a class Matrix. The class should have the flexibility to add more than two oprands without changing any operand on Left hand side of the '=' operator.
The game is going to be an RPG where you take turns attacking enemies. Your character will be able to attack/defend/use item/run/use magic spell. For now, we just want the bare basics - for a character to be able to do a generic attack and to be able to fight a generic enemy (so we're not worried about items and such things yet).
Our cpp files are: hero.cpp (which is actually the main file... and should be renamed to something better, admittedly), enemyStats.cpp (contains a class for enemies that lets you declare its HP/attack/etc), playerStats.cpp (see previous; but for your character) and attack.cpp, which contains the following:
int attackFunction(player myPlayer, enemy myEnemy) { print("Your player attacked for %d damage, bringing the wolf down to %d HP.", myPlayer.getAttack(), myEnemy.getCurrentHealth-myPlayer.getAttack()); }
We barely started, but we're already stuck on that part. I managed to make the program run just fine in terms of giving the player and enemy stats and reading it, but whenever I try to run this code in my hero.cpp (inside of main):
attackFunction(warrior, wolf);
it tells me that "enemy" has not been declared.
If I run the same code, but without any references to the wolf/enemy (so just warrior/myPlayer), it runs perfectly fine. Likewise, the program runs perfectly fine if I don't use attack.cpp and put the function directly inside of the main hero.cpp folder.
I need an array of class objects but am unsure of how one might accomplish this. I have so far...
//element class driver code Element Arsenic(lowCeiling, highCeiling); Element Cadmium(lowCeiling, highCeiling); Element Chromium(lowCeiling, highCeiling); Element Copper(lowCeiling, highCeiling); Element Lead(lowCeiling, highCeiling); Element Nickel(lowCeiling, highCeiling); Element Molybdenum(lowCeiling, highCeiling); Element Mercury(lowCeiling, highCeiling); Element Selenium(lowCeiling, highCeiling); Element Zinc(lowCeiling, highCeiling);