Hello all,
I am in need of some assistance for this assignment
I am having a problem fixing this to compile correctly. I am getting errors with line 30,31,32 of main involving the operands (They are underlined signaling errors). I am not sure why I am getting these errors? What do I need to do to correct the errors. Thanks for your time in advance!
Here are the errors:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
Error 2 error C3867: 'Serial::getSerialNumber': function call missing argument list; use '&Serial::getSerialNumber' to create a pointer to member
Error 3 error C3867: 'Serial::getSerialNumber': function call missing argument list; use '&Serial::getSerialNumber' to create a pointer to member
4 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << void
5 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << void
6 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << void
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
|
//Programming Assignment 3: Class Variable
//1. Create a class named Serial that includes a data member that holds a "serial number" for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on.
//2. A class variable should be used to contain the current serial number that is to be applied to the next created object.
//3. Add a member function that permits an object to report its own serial number.
//4. Write your class in a file named Serial.h.
// ***Output***: Write a main() program that creates three objects and displays the serial numbers assigned to each object using the following code :
//cout << "object 1 serial number is " << object1.getSerialNumber() << endl;
//cout << "object 2 serial number is " << object2.getSerialNumber() << endl;
//cout << "object 3 serial number is " << object3.getSerialNumber() << endl;
#include "Serial.h"
#include <iostream>
using namespace std;
int Serial::counter = 0;
int main()
{
Serial object1; //creating first object for class Serial
Serial object2; // creating another object for class Serial
Serial object3; // creating third object for class Serial
cout << "object 1 serial number is " << object1.getSerialNumber() << endl; //calling them from method getSerialNumber
cout << "object 2 serial number is " << object2.getSerialNumber() << endl;
cout << "object 3 serial number is " << object3.getSerialNumber() << endl;
system("pause");
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
using namespace std;
class Serial
{
public:
static int counter;
int number;
//constructor
public:Serial()
{
number = ++counter;
}
void getSerialNumber()
{
cout << "I am object number " << number << endl;
}
};
|