私はクラスのプログラムをやっていて、先生は私たちが実装しなければならなかったCppファイルを私たちにくれました。メイン以外はすべて彼によって書かれましたが、奇妙なエラーが発生します。どんな助けでも素晴らしいでしょう。これが私のコードです。
// **************************************************************************
//
// Counter.cpp
//
// Defines and tests class CounterType, which is used to count things.
// CounterType contains both a default constructor and a constructor that
// sets the count to a specified value, plus methods to increment, decrement,
// return, and output the count. The count is always nonnegative.
//
// **************************************************************************
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
class CounterType
{
public:
CounterType();
//Initializes the count to 0.
CounterType(int initCount);
//Precondition: initCount holds the initial value for the count.
//Postcondition:
// If initCount > 0,initializes the count to initCount.
// If initCount <= 0,initializes the count to 0.
void increment();
//Postcondition:
// The count is one more than it was.
void decrement();
//Postcondition:
// If the count was positive, it is now one less than it was.
// If the count was 0, it is still 0
int getCount();
void output(ostream& outStream);
//Precondition: outStream is ready to write to
//Postcondition: count has been written to outStream
private:
int count;
};
void increment();
void decrement();
int getCount();
void output(ostream& outStream);
int main()
{
CounterType Test;
increment();
decrement();
getCount();
}
CounterType::CounterType()
{
count = 0;
}
CounterType::CounterType(int initCount)
{
if (initCount >= 0)
count = initCount;
else
count = 0;
}
void CounterType::increment()
{
count++;
}
void CounterType::decrement()
{
if (count > 0)
count--;
}
int CounterType::getCount()
{
return count;
}
void CounterType::output(ostream& outStream)
{
outStream << count;
}
そして、ここにエラーがあります。
エラー1エラーLNK2028:未解決のトークン(0A000330) "void __cdecl decrement(void)"(?decrement @@ $$ FYAXXZ)が関数 "int __cdecl main(void)"(?main @@ $$ HYAHXZ)J:\で参照されていますMCM 10.05 \ MCM 10.05 \ MCM10.obj MCM 10.05