2016-12-17 23 views
0

C++でObject Orientedを学び始めました。 私の最初のレッスンで、そのエラー"iostreamファイルが見つかりません"を受け取りました。 私は、コーディングのためにFedora 24とア​​トムエディタを使用します。私はコマンドg++ main.cpp -o aことを使用したビルドのために 私もインストール原子のプラグインiostreamファイルが見つかりません

gpp-compiler 

私の主なファイルは次のとおりです。

#include <iostream> 
#include <string> 
#include "BMI.h" 

using namespace std; 

int main(){ 
     string name; 
     int height; 
     double weight; 

     cout << "Enter your name: "; 
     cin >> name; 

     cout << "Enter your height (in inches): "; 
     cin >> height; 

     cout << "Enter your weight: "; 
     cin >> weight; 
     BMI a; 
     // BMI Student_1(name, height, weight); 

     return 0; 
} 

私はそれが動作BMIオブジェクトなしでメインファイルを実行したとき。 しかし、main関数にBMIオブジェクトを追加すると、出力はエラーになります。

私のBMIオブジェクト: ヘッダファイル:

#include <iostream> 
#include <string> 

using namespace std; 

#ifndef BMI_H 
#define BMI_H 

class BMI { 
public: 
//Default Constructor 
     BMI(); 
//Overload Constructor 
     BMI(string, int, double); 
private: 
//Member Variable 
     string newName; 
     int newHeight; 
     double newWeight; 
}; 


#endif 

CPPファイル:

#include "BMI.h" 

BMI::BMI(){ 
    newName = "aa"; 
    newHeight = 0; 
    newHeight = 0.0; 
} 

BMI::BMI(string name, int height, double weight){ 
    newName = name; 
    newHeight = height; 
    newWeight = weight; 
} 

疑問は、なぜそれが動作しませんされて https://www.youtube.com/watch?v=vz1O9nRyZaY

からこのチュートリアルで、なぜそれをBMIオブジェクトなしで動作しますか?

ありがとう、マイケル。

+3

? – StoryTeller

+0

おそらく、学習する最良の方法は本を読むことです。ここには[C++の本](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)の素敵なリストがあります。 –

+0

g ++ main.cpp -oa出力は/tmp/ccM9rMj9.oです。関数mainにあります。 main.cpp :(。テキスト+ 0x7d):未定義のBMI :: BMI()への参照 collect2:エラー:ldが1の終了ステータスを返しました –

答えて

1

あなたのcppファイル内のエラーを入力しています

newHeight = 0; 
newHeight = 0.0; // <- error 

試してください:どのようにあなたのプログラムを構築している

newHeight = 0; 
newWeight = 0.0; 
関連する問題