我使用G ++ cygwin的版本,我試圖編譯一個.cpp文件,但我遇到了錯誤編譯C++文件,錯誤使用G ++
這裏是代碼:
#include "randomc.h"
#include <time.h> // Define time()
#include <stdio.h> // Define printf()
#include <cstdlib>
int main(int argc, char *argv[]) {
int seed = atoi(argv[1]);
int looptotal = atoi(argv[2]);
//initializes rng, I want to use argv[1] to set seed
void CRandomMother::RandomInit (int seed) {
int i;
// loop for the amount of times set by looptotal and return random number
for (i = 0; i < looptotal; i++) {
double s;
s = Random();
printf("\n%f", s)
}
}
return 0;
}
這裏錯誤我正在嘗試使用cygwin的終端和g ++
[email protected] /cygdrive/c/xampp/xampp/htdocs$ g++ ar.cpp -o prog
ar.cpp: In function `int main(int, char**)':
ar.cpp:13: error: a function-definition is not allowed here before '{' token
ar.cpp:13: error: expected `,' or `;' before '{' token
.cpp文件和頭文件randomc.h編譯時,位於我的XAMPP位置。我認爲這不重要,應該嗎?有人能告訴我如何讓這個編譯和運行嗎?謝謝。
爲什麼你想定義'CRandomMother ::'main'內RandomInit'? – 2012-02-29 16:11:51
在嘗試任何更復雜的事情之前,您需要真正學習基本的C++語法。 – Naveen 2012-02-29 16:13:08
謝謝,今天過後我將學習更多關於C++的知識。我猜是因爲我開始使用PHP,我不習慣輕易改變。 – 2012-02-29 16:21:18