2016-06-19 13 views
-4

私は私は適切な解決策で答える私を与えるこのquestion.Pleaseに適切solution.Iも追加のエラー画像を見つけることができませんでしたよC++ で初心者レベルの学生です助けてください。このシンプルなC++クラスプログラムで何が問題になっていますか?

#include <iostream> 
#include <conio.h> 

class test 
{ 
    int no; 
    static int count; 
    public: 
     void getval (int); 
     void dispcount (void); 

}; 

void test:: getval(int x) 
{ 
    no = x; 
    cout << "Number = " << no << endl;; 
    count++; 
} 

void test::dispcount(void) 
{ 
    cout << "Counten = " << count; 
} 
    int test::count; 

int main() 
{ 
    test t1,t2,t3; 

    t1.dispcount(); 
    t2.dispcount(); 
    t3.dispcount(); 

    t1.getval(100); 
    t2.getval(200); 
    t3.getval(300); 

    t1.dispcount(); 
    t2.dispcount(); 
    t3.dispcount(); 
    getch(); 
    return 0; 
} 

here is error.jpg

+1

適切な解決策を見つけるには、問題を特定する必要があります。あなたはそうしましたか? –

+3

あなたの質問に、このような質問に読みにくい画像を含めないでください。エラーメッセージをプレーンテキストとして含める必要があります。 C++の初心者のために、あなたが学ぶ必要がある最高のスキルは、他のみんながあなたを理解できるようにあなたの問題を伝える方法です。 –

+0

'std :: cout << ...'を使います。 –

答えて

1

ディレクティブ

#include <iostream> 
#include <conio.h> 

using namespace std; 
//.. 

含めるなど使用して宣言を含める

#include <iostream> 
#include <conio.h> 

using std::cout; 
using std::endl; 
//... 

または、例えばとして修飾名を使用し

void test:: getval(int x) 
{ 
    no = x; 
    std::cout << "Number = " << no << std::endl; 
    ^^^^^^^^^       ^^^^^^^^^^ 
    count++; 
} 

識別子coutおよびendlは、ネームスペースstdで宣言され、グローバル名前空間では宣言されません。

+4

初級C++プログラマは、「using namespace std;」のような悪いプログラミング習慣に実際にさらされるべきではありません。(http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-in-c-considered -bad-practice)。 –

+0

@SamVarshavchik私はusingディレクティブを使ってC++を学び始めると確信しています。そして、どんな場合でも、プログラマーはすべての可能性を知っているべきです。 –

+0

あなたは素晴らしいです..... –

関連する問題