C ++:将程序转移到标题中

时间:2014-01-31 10:49:14

标签: c++ class object header main

我是C ++的新手,我得到了一个名为sendSMS的程序:

#include "ServerSocket.h"
#include "SocketException.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include "Socket.h"
#include <pthread.h>
#include <stdio.h>
#include "Config.h"
#include <mysql/mysql.h>
#include <cstdlib>
#include <SerialStream.h>

void *func_servidor(void *ptr_timer);

ServerSocket server(30001);

pthread_t thread_servidor;
pthread_t thread_transfdados;
pthread_t thread_BD;

pthread_cond_t cv;
pthread_mutex_t mp;

int ret;


#define CTRL_C "\x1A"

const int PORT_MON = 30000;

const string serialPort = "/dev/ttyS0";


using namespace LibSerial;
using namespace std;


int setSerial(SerialStream& ssStream, const string& port) {
...
....
}

int sendsms(int argc, char **argv) {
bool send = true;
...
....
return(0);
}

void *func_servidor(void *ptr)
{
...
....
return(0);
}

我想将所有这些函数传递到头文件.h文件并在主程序(main.cpp)中调用它,因此main.cpp只调用“所有内容”,如:

#include sendSMS.h

class modem{
{
     public:
       void SendSms();
}

int main{
  SendSms();
  return(0);
}

标题会是什么样的?

#ifndef __SENDSMS__ 
#define __SENDSMS__ 

#include "ServerSocket.h"
#include "SocketException.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include "Socket.h"
#include <pthread.h>
#include <stdio.h>
#include "Config.h"
#include <mysql/mysql.h>
#include <cstdlib>
#include <SerialStream.h>

class sendsms
{
    private:
    int ret;
    const int PORT_MON;
    int argc;
    const string serialPort;
    char **argv;
    bool send;

    public:
    sendsms();
    void *func_servidor(void *ptr);
    int setSerial(SerialStream& ssStream, const string& port);
    int  sendsms();

};

#endif

1 个答案:

答案 0 :(得分:0)

在main.cpp中,您需要一个modem类型的对象才能从sendsms()拨打main()

#include sendSMS.h

class modem{
{
     public:
       void SendSms();
}

int main(int argc, char **argv) {
    modem m;
    m.SendSms();
    return(0);
}