0

I am writing a program implementing go-back n arq bidirectional using windows server. but i got conflicted in the lines I posted down here. I declared size as int and it is global variable but seems not to be working this way perhaps. any ideas

#include <stdlib.h>
#include <time.h>
#include <WinSock2.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <io.h> 

using namespace std;

#pragma comment(lib,"ws2_32.lib")

#define SERVER_PORT  12340  
#define SERVER_IP  "127.0.0.1" 

const int BUFFER_LENGTH = 1026;
const int SEND_WIND_SIZE = 15;
const int SEQ_SIZE = 20;
BOOL ack[SEQ_SIZE];

int curSeq;
int curAck;
int totalSeq;
int totalPacket;
int size;
int flag = 0;
int checksum;

int main(int argc, char* argv[]) {

/*other part here not affected*/

>but from down there it says size is ambigus

   FILE* file;
    fopen_s(&file, "./test.txt", "rb");
    size = _filelength(_fileno(file));
    printf("Open the files%d \n", size);
    fclose(file);

    //char data[1024 * 113];
    char* data = new char[size];
    ZeroMemory(data, sizeof(data));
    icin.read(data, size);
    icin.close();
}
  1. I declare it previously as global variable
  2. Here is the error message:
Severity    Code    Description Project File    Line    Suppression State Error
(active)    E0266   "size" is ambiguous

I also have removed it from global declaration and yet still highlighting an error

James K. Lowden
  • 7,574
  • 1
  • 16
  • 31
  • In case you find the duplicate hard to read: `using namespace std;` makes `size` come in conflict with with `std::size`. – Ted Lyngmo May 04 '21 at 17:40
  • That's why one should avoid importing entire namespaces (see [this question](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)) and avoid global variables as much as possible. – Aconcagua May 04 '21 at 17:43
  • This should be the new question we link to when people ask why `using namespace std;` is bad. It's a real-world practical example of a collision. – Casey May 04 '21 at 17:54

0 Answers0