「メイン」ファイル内に別のファイルの関数を含めようとしています。私はこのパラダイムに従っています:
http://www.learncpp.com/cpp-tutorial/18-programs-with-multiple-files/
これが私のメイン ファイル、digispark.cpp です。
#include <iostream>
using namespace std;
int send(int argc, char **argv);
int main()
{
char* on;
*on = '1';
char* off;
*off = '0';
send(1,&on);
return 0;
}
そして、ここに私のsend.cppがあります:
#include <stdio.h>
#include <iostream>
#include <string.h>
#if defined WIN
#include <lusb0_usb.h> // this is libusb, see http://libusb.sourceforge.net/
#else
#include <usb.h> // this is libusb, see http://libusb.sourceforge.net/
#endif
// I've simplified the contents of send for my debugging and your aid, but the
// complicated arguments are a part of the function that will eventually need
// to be here.
int send (int argc, char **argv)
{
std::cout << "Hello";
return 0;
}
次のように g++ コンパイラを使用して、Ubuntu 12.10 でコンパイルしています。
g++ digispark.cpp send.cpp -o digispark
正常にコンパイルされます。
しかし、プログラムを実行すると、「Hello」が表示されません。したがって、関数がまったく呼び出されているとは思いません。私は何を間違っていますか?どんな助けでも素晴らしいでしょう!ありがとう!
編集:
この問題への対処方法:
int send(int argc, char **argv);
int main()
{
char* on[4];
on[0] = (char*)"send";
on[1] = (char*)"1";
char* off[4];
off[0] = (char*)"send";
off[1] = (char*)"0";
send(2,on);
return 0;
}
なぜ私がそうしなければならないのか混乱していた方のために説明すると、前に述べたように、send 関数はすでに char** argv (または char* argv[]) を受け入れるように構築されています。私のポイントは、メイン関数でそれを模倣しようとすることでした。
実際に送信関数に入る関数を書き直して、必要なものを単に送信するよりも、異なるタイプの引数を取る方がはるかに困難だったでしょう。みんな、ありがとう!
したがって、これが同様のことをしようとしている人に役立つ場合は、気軽に使用してください!