1 Replies - 131 Views - Last Post: 19 August 2019 - 02:33 AM Rate Topic: -----

#1 GreenSage1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-August 19

Compiler Error C2679

Posted 19 August 2019 - 02:00 AM

I keep getting:
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) when I compile my program. I have no idea why its happening.Can anyone tell me why the program isn't compiling? Thanks in advance!

#include "Projectiles.h"
#include "Ai_Manager.h"

using namespace std;
using namespace sf;

struct WeaponDamage
{
	int min;
	int max;
};

class Weapons
{
protected:
	string name;
	int maxAmmo;
	int currentAmmo;
	WeaponDamage dmg;



#include "Glock.h"

Glock::Glock()
{
	dmg = 25;
	maxAmmo = 20;
	currentAmmo = maxAmmo;
	reloadingTime = seconds(1);
	fireSpeed = milliseconds(500);



#include "Survival.h"
#include "AK.h"



AK::AK()
{
	dmg = 50;
	maxAmmo = 30;
	currentAmmo = maxAmmo;
	reloadingTime = seconds(1.5);
	fireSpeed = milliseconds(100);



Is This A Good Question/Topic? 0
  • +

Replies To: Compiler Error C2679

#2 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7469
  • View blog
  • Posts: 15,489
  • Joined: 16-October 07

Re: Compiler Error C2679

Posted 19 August 2019 - 02:33 AM

Well, with only code snippets, any answer is little more than a guess.

Still, it looks like you're doing this:
struct WeaponDamage {
    int min, max;
};

int main() {
    WeaponDamage dmg = 25;
    return 0;
}



At which point, you'd expect to get this:
5:24: error: conversion from 'int' to non-scalar type 'WeaponDamage' requested



Since it's a simple struct, you could force this with something like WeaponDamage dmg = {20, 25};. However it would be far preferable to implement proper constructors. At which point it will compile with one value, if you allow for it.

struct WeaponDamage {
    int min, max;
    WeaponDamage(int);
    WeaponDamage(int, int);
};

int main() {
    WeaponDamage dmg = 25;
    return 0;
}

// your implementation code for the constructors here



Hope this helps.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1