linker error undefined reference
Sep 28, 2013 at 12:29am UTC
The output count function is giving me a killer headache can someone please tell whats wrong with this function. The problem calls for a function called outputCount that has one formal parameter ostream. When I run my code I just get a error that says "[Linker error] undefined reference to `CounterType::outputCount(std::ostream&)' " So what did i do wrong? please help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include <iostream>
using namespace std;
class CounterType
{
int count;
public :
CounterType();
CounterType(int );
int getCount();
void outputCount(ostream&);
int plusOne();
int minusOne();
};
CounterType::CounterType () : count(0)
{}
CounterType::CounterType(int )
{}
int CounterType::getCount()
{
return count;
}
int CounterType::plusOne()
{
count++;
return count;
}
int CounterType::minusOne()
{
count--;
return count;
}
void outputCount(ostream&)
{
cout << count;
}
int main( )
{
cout << "Testing the CounterType class" ;
CounterType testOne, testTwo(50);
cout << "\n\nInitial Values:\n" << testOne.getCount() << " " ;
testTwo.outputCount(cout);
while (testOne.getCount() < 30)
testOne.plusOne();
while (testTwo.getCount() > 30)
testTwo.minusOne();
cout << "\n\nFinal Values:\n" << testOne.getCount() << " " ;
testTwo.outputCount(cout);
system("pause" );
return 0;
}
Last edited on Sep 28, 2013 at 12:34am UTC
Sep 28, 2013 at 12:35am UTC
Line 38 CounterType::
is missing.
Topic archived. No new replies allowed.