I am working on this assignment, compiler is giving me 2 errors but I couldn't find any mistakes.

#include<iostream>
using std::cout;
using std::endl;

class opOverload
{
public:
	opOverload();
	opOverload(int,int);
	opOverload operator+(opOverload);
	void show();
private:
	int sub1;
	int sub2;
};
#include<iostream>
using std::cout;
using std::endl;

#include"opOverload.h"

//default constructor
opOverload::opOverload()
{
}

opOverload::opOverload(int a, int b)
{
	sub1 = a;
	sub2 = b;
}

//opeartor overloading begins here
opOverload opOverload:: operator+(opOverload obj)
{
	opOverload temp;

	temp.sub1 = sub1 + obj.sub1;
	temp.sub2 = sub2 + obj.sub2;
	return temp;
}
#include<iostream>
using std::cout;
using std::endl;

# include "opOverload.h"

void main()
{
	opOverload obj1 = (10,20);
	opOverload obj2 = (30,40);

	obj1 = obj1 + obj2;
	obj1.show();
}

1>driver.cpp
1>c:\users\owner\documents\visual studio 2008\projects\arrays\arrays\driver.cpp(9) : error C2440: 'initializing' : cannot convert from 'int' to 'opOverload'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\owner\documents\visual studio 2008\projects\arrays\arrays\driver.cpp(10) : error C2440: 'initializing' : cannot convert from 'int' to 'opOverload'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>opOverload.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Users\Owner\Documents\Visual Studio 2008\Projects\Arrays\Arrays\Debug\BuildLog.htm"
1>Arrays - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

opOverload obj1 = (10,20);
opOverload obj2 = (30,40);

should probably be

opOverload obj1(10,20);
opOverload obj2(30,40);
This article has been dead for over six months. Start a new discussion instead.