We help IT Professionals succeed at work.
Get Started

Constructing an object with three different member variables

ambuli
ambuli asked
on
251 Views
Last Modified: 2012-06-27
Hi Experts,

I have to provide an API to users who need to send some command to the server.
the commands will be of the form
class API
{
   void sendWrite()
   void sendUpdate()
   void sendRead()
   void sendDelete()
};


I need to construct an object with the following which is the command to be send to a server.  The command is of this form(i.e, three separate lines with the following format)
msg:::write
id:::123
data::dataValue

msg is one of  write, read, delete, update, etc.  
id is not relevant for now.
The dataValue may be a string, int or a json encoded string. I will be setting this data field according the command.

I have another class that actually send this string to the server.

bool cmdSender::sendCommand()
{

}

What I am trying to do is to create the commandMsgs and
do something like
sender->sendCommand(cmd.getString());

So, I need to create a Command class and constuct it as per the request.  What is the better way to do it.

class Command
{
       

}

So, I need to create the Command objects by simply passing

Command *cmd = new Command(write, 123, dataValueString);
then call sendCommand(cmd->getString())  or something like this.  
Comment
Watch Question
Senior Software Engineer (Avast)
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 3 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE