Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:16:45+00:00 2026-06-10T15:16:45+00:00

i have following class with overloading operators #include<iostream> #include<algorithm> #include<math.h> using namespace std; class

  • 0

i have following class with overloading operators

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
class Cvector
{
public:
    int x,y;
    Cvector() {  x=0;y=0;}
    Cvector(int,int);
    Cvector operator+(Cvector);
    Cvector operator-(Cvector);
    int  operator*(Cvector);
    bool operator==(Cvector);
    Cvector operator*(int);
    Cvector operator=(Cvector);

    int cross_multiplication(Cvector,Cvector);
    float  norm();

    };
Cvector Cvector::operator=(Cvector a)
{
    x=a.x;
    y=a.y;
    return *this;

}
bool Cvector::operator==(Cvector b)
{
    return (x==b.x && y==b.y);

}

Cvector Cvector::operator*(int c)
{
    Cvector temp;
    temp.x=c*x;
    temp.y=c*y;
    return temp;

}
float Cvector::norm()
{
    float result=0;
    result+=x*x+y*y;;
    return sqrt(result);


}
Cvector::Cvector(int a,int b)
{
    x=a;
    y=b;

}
Cvector Cvector::operator+(Cvector a)
{
    Cvector temp;
    temp.x=x+a.x;
    temp.y=y+a.y;
    return temp;

}
Cvector Cvector::operator-(Cvector b)
{
    Cvector temp;
    temp.x=x-b.x;
    temp.y=y-b.y;
    return temp;

}
int Cvector::operator*(Cvector a)
{
    return x*a.x+y*a.y;


}

int main()
{
    Cvector a(3,4);
    Cvector b(4,5);
    cout<<b.norm()<<endl;
    Cvector c;
    c=a*b;
    cout<<(a==b)<<endl;

    return 0;
}

but it gives me one error

1>c:\users\dato\documents\visual studio 2010\projects\point_class\point_class\point_class.cpp(86): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1>          c:\users\dato\documents\visual studio 2010\projects\point_class\point_class\point_class.cpp(16): could be 'Cvector Cvector::operator =(Cvector)'
1>          while trying to match the argument list '(Cvector, int)'

please help me to fix this problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:16:47+00:00Added an answer on June 10, 2026 at 3:16 pm

    Root Cause:

    int Cvector::operator*(Cvector a)
    

    returns an int, so:

    c=a*b;
    

    tries to assign an int to a Cvector object, which needs a overloaded = operator of Cvector class to take int as parameter, which it doesn’t. Hence the error.

    Suggested Solution:

    c has no business being a Cvector, it should be an int ideally, so either it could be a typo or it could indeed be the intent(which does break conventional algebraic wisdon).I am not sure which one it is.

    If it is the former, just change type of c to int.

    If it is latter, You need to provide a constructor which takes in an int parameter:

    Cvector::Cvector(int)
    {
    
    }
    

    This constructor will implicitly called to convert the int result of operator * and convert it to an Cvector object which will then be used to call the operator =.

    Online Demo of your code with suggested solution

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following code: class Array { public: int aaa; Array():aaa(1){} void print()
I have the following code: class A { public: A() {}; void operator[](int x)
In the following codes, I illustrate an example of operator overloading: #include <iostream> using
I have following class (as seen through reflector) public class W : IDisposable {
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
I have the following class public class MenuVeiculo { public string Nome { get;
I have encountered the following code: class a { public: void * operator new(size_t
Background Let's say I have the following class: public class MyValue<T> { public T
The following codes try to show how to overload assignment operator: #include <iostream> using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.