10 Replies - 597 Views - Last Post: 29 April 2009 - 12:49 PM Rate Topic: -----

#1 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Consequences of Inline Methods

Post icon  Posted 27 April 2009 - 09:05 PM

Is it true that having a class with inline methods will cause multiple inclusion headers to become insufficient anymore?

The reason I ask is because I think that may be the reason to a "multiple declarations" error I am receiving.

Before i edit the source code (I didn't write it) to move the method implementation outside the class, I would like to make sure that this theory is correct.

Thank you.

This post has been edited by e_barroga: 27 April 2009 - 09:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Consequences of Inline Methods

#2 BlakeJustBlake  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 26
  • View blog
  • Posts: 441
  • Joined: 15-February 09

Re: Consequences of Inline Methods

Posted 27 April 2009 - 10:13 PM

How is it written inside the class?

Are you using an inclusion guard?
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: Consequences of Inline Methods

Posted 28 April 2009 - 03:42 AM

You will get a multiple declaration error regardless of whether the methods are inlined or not.

Remember you declare in the header and implement in the implementation (usually).

The issue is the declaration step and, as BlakeJustBlake has pointed out, the answer is to use the #ifndef, #define, #endif wrappers to prevent such pre-processor problems.

http://www.fredosaur...ssor/ifdef.html

This post has been edited by janotte: 28 April 2009 - 03:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Consequences of Inline Methods

Posted 28 April 2009 - 07:23 AM

It already has inclusion guard. Before it had pragma once but I changed it.

I've got the "networking library" which consists of multiple headers and source files:
includes.h //includes certain standard libraries needed
socket.h
buffer.h
tools.h
list.h


The headers also have inclusion guards.

I was actually wrong, the declarations are all done in the header files. The implementations are separated into the corresponding .cpp files.
socket.cpp (includes socket.h)
buffer.cpp (includes buffer.h)
tools.cpp (etc.)
list.cpp (etc.)



I have a header file that defines global functions/variables and uses the networking library, it has the following headers:
//FUNCTIONS.H
#include "includes.h"
#include "tools.h"
#include "socket.h"
#include "buffer.h"
#include "list.h"


It also has inclusion guards. All the functions have their implementation inside and no .cpp file is used here.

This header file simplifies the networking library to use variables instead of classes. For example, to listen on a certain port for new connections I could do:
mainSocket = tcplisten( 12564, 10, 1 );



Opposed to first creating the objects, etc., etc.
CSocket sock;
CBuffer buff;
mainSocket = sock.tcplisten(12564, 10, 1);



Then I have an Engine header. It includes the Functions.h file.

Then I have a "Headers.h" file, it includes STLs I'll be using and additional headers I'll be using:
//STL
#include <iostream>
#include <vector>
#include <fstream>

#include "Engine.h"

#include "Player.h"



My main just includes that single "Headers.h" file.


I think if I modify the "Functions file" so that I define prototypes in the header file and move the implementation to a .cpp file, it'll work. But I don't see why, isn't it still being called once (by Engine.h)?

Here's the error I am receiving:

Error said:

obj\Debug\main.o||In function `_Z10tcpconnectPcdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|19|multiple definition of `tcpconnect(char*, double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|19|first defined here|
obj\Debug\main.o||In function `_Z9tcplistenddd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|28|multiple definition of `tcplisten(double, double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|28|first defined here|
obj\Debug\main.o||In function `_Z9tcpacceptdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|37|multiple definition of `tcpaccept(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|37|first defined here|
obj\Debug\main.o||In function `_Z5tcpipd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|46|multiple definition of `tcpip(double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|46|first defined here|
obj\Debug\main.o||In function `_Z8setnagledd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|53|multiple definition of `setnagle(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|53|first defined here|
obj\Debug\main.o||In function `_Z12tcpconnectedd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|63|multiple definition of `tcpconnected(double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|63|first defined here|
obj\Debug\main.o||In function `_Z10udpconnectdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|71|multiple definition of `udpconnect(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|71|first defined here|
obj\Debug\main.o||In function `_Z11sendmessagedPcdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|80|multiple definition of `sendmessage(double, char*, double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|80|first defined here|
obj\Debug\main.o||In function `_Z14receivemessageddd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|91|multiple definition of `receivemessage(double, double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|91|first defined here|
obj\Debug\main.o||In function `_Z11peekmessageddd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|107|multiple definition of `peekmessage(double, double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|107|first defined here|
obj\Debug\main.o||In function `_Z9setformatddPc':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|123|multiple definition of `setformat(double, double, char*)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|123|first defined here|
obj\Debug\main.o||In function `_Z8lastinIPv':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|130|multiple definition of `lastinIP()'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|130|first defined here|
obj\Debug\main.o||In function `_Z10lastinPortv':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|135|multiple definition of `lastinPort()'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|135|first defined here|
obj\Debug\main.o||In function `_Z7setsyncdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|140|multiple definition of `setsync(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|140|first defined here|
obj\Debug\main.o||In function `_Z9closesockd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|148|multiple definition of `closesock(double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|148|first defined here|
obj\Debug\main.o||In function `_Z13socklasterrord':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|157|multiple definition of `socklasterror(double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|157|first defined here|
obj\Debug\main.o||In function `_Z6myhostv':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|164|multiple definition of `myhost()'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|164|first defined here|
obj\Debug\main.o||In function `_Z9compareipPcS_':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|169|multiple definition of `compareip(char*, char*)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|169|first defined here|
obj\Debug\main.o||In function `_Z8sockexitv':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|174|multiple definition of `sockexit()'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|174|first defined here|
obj\Debug\main.o||In function `_Z9sockstartv':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|180|multiple definition of `sockstart()'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|180|first defined here|
obj\Debug\main.o||In function `_Z6hostipPc':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|186|multiple definition of `hostip(char*)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|186|first defined here|
obj\Debug\main.o||In function `_Z11getsocketidd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|191|multiple definition of `getsocketid(double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|191|first defined here|
obj\Debug\main.o||In function `_Z9writebytedd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|199|multiple definition of `writebyte(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|199|first defined here|
obj\Debug\main.o||In function `_Z10writeshortdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|206|multiple definition of `writeshort(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|206|first defined here|
obj\Debug\main.o||In function `_Z11writeushortdd':|
C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|213|multiple definition of `writeushort(double, double)'|
obj\Debug\Player.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.h|213|first defined here|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|

This post has been edited by e_barroga: 28 April 2009 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

#5 BlakeJustBlake  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 26
  • View blog
  • Posts: 441
  • Joined: 15-February 09

Re: Consequences of Inline Methods

Posted 28 April 2009 - 08:57 AM

What I'm thinking: I didn't really pay too much attention to the structure of your whole "this is included here and that's included there." But check to see if this is happening: the header file where things are implemented may have inclusion guards, but is included in two separate files that are both included in another file. So both of those files have the definitions, and then they're pushed together and start to have problems. The inclusion guards really only help you from compile time problems, but this is a linking problem. Moving the implementation to a cpp file will probably fix this.

This post has been edited by BlakeJustBlake: 28 April 2009 - 09:10 AM

Was This Post Helpful? 0
  • +
  • -

#6 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Consequences of Inline Methods

Posted 28 April 2009 - 09:01 AM

#ifndef DLL_H_INCLUDED
#define DLL_H_INCLUDED

#include "includes.h"
#include "tools.h"
#include "socket.h"
#include "buffer.h"
#include "list.h"

CList buffers;
CList sockets;
CList files;
int AddSocket(CSocket*);
int AddBuffer(CBuffer*);
int AddFile(HANDLE);

//Sockets
double tcpconnect(char*ip, double port, double mode)
{
	CSocket* sock = new CSocket();
	if(sock->tcpconnect(ip, (int)port, (int)mode))
		return AddSocket(sock);
	delete sock;
	return -1;
}

double tcplisten(double port, double max, double mode)
{
	CSocket* sock = new CSocket();
	if(sock->tcplisten((int)port, (int)max,(int)mode))
		return AddSocket(sock);
	delete sock;
	return -1;
}

double tcpaccept(double sockid, double mode)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	CSocket*sock2 = sock->tcpaccept((int)mode);
	if(sock2 != NULL)return AddSocket(sock2);
	return -1;
}

char* tcpip(double sockid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return NULL;
	return sock->tcpip();
}

double setnagle(double sockid, double value)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return 0;
	if(value)
		sock->setnagle(true);
	else sock->setnagle(false);
	return 1;
}

double tcpconnected(double sockid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return 0;
	if(sock->tcpconnected())return 1;
	else return 0;
}

double udpconnect(double port, double mode)
{
	CSocket* sock = new CSocket();
	if(sock->udpconnect((int)port, (int)mode))
		return AddSocket(sock);
	delete sock;
	return -1;
}

double sendmessage(double sockid, char*ip, double port, double buffid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(sock == NULL)return -1;
	if(buff == NULL)return -2;
	int size = sock->sendmessage(ip, (int)port, buff);
	if(size < 0)return -sock->lasterror();
	return size;
}

double receivemessage(double sockid, double len, double buffid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(sock == NULL)return -1;
	if(buff == NULL)return -2;
	int size = sock->receivemessage((int)len, buff);
	if(size < 0)
	{
		int error = sock->lasterror();
		if(error == 10054)return 0;
		return -error;
	}
	return size;
}

double peekmessage(double sockid, double len, double buffid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(sock == NULL)return -1;
	if(buff == NULL)return -2;
	int size = sock->peekmessage((int)len, buff);
	if(size < 0)
	{
		int error = sock->lasterror();
		if(error == 10054)return 0;
		return -error;
	}
	return size;
}

double setformat(double sockid, double mode, char*sep)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	return sock->SetFormat((int)mode, sep);
}

char* lastinIP()
{
	return CSocket::lastinIP();
}

double lastinPort()
{
	return CSocket::lastinPort();
}

double setsync(double sockid, double mode)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	sock->setsync((int)mode);
	return 1;
}

double closesock(double sockid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	delete sock;
	sockets.set((int)sockid, NULL);
	return 1;
}

double socklasterror(double sockid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	return -sock->lasterror();
}

char* myhost()
{
	return CSocket::myhost();
}

double compareip(char*ip, char*mask)
{
	return CTools::comparematch(ip, mask);
}

double sockexit()
{
	CSocket::SockExit();
	return 1;
}

double sockstart()
{
	CSocket::SockStart();
	return 1;
}

char* hostip(char*host)
{
	return CSocket::GetIp(host);
}

double getsocketid(double sockid)
{
	CSocket*sock = (CSocket*)sockets.item((int)sockid);
	if(sock == NULL)return -1;
	return sock->sockid;
}

//Buffers
double writebyte(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writebyte((unsigned char)val);
}

double writeshort(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writeshort((short)val);
}

double writeushort(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writeushort((unsigned short)val);
}

double writeint(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writeint((int)val);
}

double writeuint(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writeuint((unsigned int)val);
}

double writefloat(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writefloat((float)val);
}

double writedouble(double val, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writedouble(val);
}

double writechars(char*str, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writechars(str);
}

double writestring(char*str, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->writestring(str);
}

double readbyte(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readbyte();
}

double readshort(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readshort();
}

double readushort(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readushort();
}

double readint(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readint();
}

double readuint(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readuint();
}

double readfloat(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readfloat();
}

double readdouble(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->readdouble();
}

char* readchars(double len, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return NULL;
	return buff->readchars((int)len);
}

char* readstring(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return NULL;
	return buff->readstring();
}

char* readsep(char*sep, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return NULL;
	return buff->readsep(sep);
}

double getpos(double pos, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	if(pos == 0)return buff->writepos;
	else return buff->readpos;
}

double clearbuffer(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	buff->clear();
	return 1;
}

double buffsize(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->count;
}

double setpos(double pos, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	buff->readpos = (int)pos;
	buff->writepos = (int)pos;
	return pos;
}

double bytesleft(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return buff->bytesleft();
}

double createbuffer()
{
	CBuffer* buff = new CBuffer();
	return AddBuffer(buff);
}

double freebuffer(double buffid)
{
	if(buffid == 0)return 0; //no deleting default buffer
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	delete buff;
	buffers.set((int)buffid, NULL);
	return 1;
}

double copybuffer(double destinationid, double sourceid)
{
	CBuffer*destination = (CBuffer*)buffers.item((int)destinationid);
	if(destination == NULL)return 0;
	CBuffer*source = (CBuffer*)buffers.item((int)sourceid);
	if(source == NULL)return 0;
	destination->addBuffer(source);
	return 1;

}

double copybuffer2(double destinationid, double start, double len, double sourceid)
{
	CBuffer*destination = (CBuffer*)buffers.item((int)destinationid);
	if(destination == NULL)return 0;
	CBuffer*source = (CBuffer*)buffers.item((int)sourceid);
	if(source == NULL)return 0;
	destination->addBuffer(source->data+(int)start, (int)len);
	return 1;

}

//tools
char* getmacaddress()
{
	return CTools::getmacaddress();
}

char* md5string(char*str)
{
	return CTools::md5string(str);
}

char* md5buffer(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return NULL;
	return CTools::md5buffer(buff);
}

double bufferencrypt(char*pass, double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	CTools::encryptedbuffer(buff, pass);
	return 1;
}

double adler32(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return CTools::adler32(buff);
}

double bufferexists(double buffid)
{
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return 0;
	return 1;
}

double netconnected()
{
	return CTools::netconnected();
}

double fileopen(char*name, double mode)
{
	HANDLE file = CTools::BinOpen(name, (int)mode);
	if(file != NULL)
		return AddFile(file);
	return -1;
}

double fileclose(double fileid)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	files.set((int)fileid, NULL);
	return CTools::BinClose(file);
}

double filewrite(double fileid, double buffid)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return -1;
	return CTools::BinWrite(file, buff);
}

double fileread(double fileid, double bytes, double buffid)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	CBuffer*buff = (CBuffer*)buffers.item((int)buffid);
	if(buff == NULL)return -1;
	return CTools::BinRead(file, (int)bytes, buff);
}

double filepos(double fileid)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	return CTools::BinGetPos(file);
}

double filesetpos(double fileid, double pos)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	return CTools::BinSetPos(file, (int)pos);
}

double filesize(double fileid)
{
	HANDLE file = (HANDLE)files.item((int)fileid);
	if(file == NULL)return -1;
	return CTools::BinFileSize(file);
}

double iptouint(char*ip)
{
	return CTools::ip2uint(ip);
}

char* uinttoip(double ip)
{
	return CTools::uint2ip((unsigned int)ip);
}

int AddBuffer(CBuffer*B)/>
{
	for(int i = 0; i < buffers.count; i ++)
	{
		if(buffers[i] == NULL)
		{
			buffers.set(i, B)/>;
			return i;
		}
	}
	buffers.Add(B)/>;
	return buffers.count-1;
}

int AddSocket(CSocket*B)/>
{
	for(int i = 0; i < sockets.count; i ++)
	{
		if(sockets[i] == NULL)
		{
			sockets.set(i, B)/>;
			return i;
		}
	}
	sockets.Add(B)/>;
	return sockets.count-1;
}

int AddFile(HANDLE B)/>
{
	for(int i = 0; i < files.count; i ++)
	{
		if(files[i] == NULL)
		{
			files.set(i, B)/>;
			return i;
		}
	}
	files.Add(B)/>;
	return files.count-1;
}

double dllInit()
{
    CSocket::SockStart();
    buffers.Add(new CBuffer());
    sockets.Add(new CSocket()); //dummy socket
    return 1;
}

double dllFree()
{
    CSocket::SockExit();
    for(int i = 0; i < buffers.count; i++)
        if(buffers[i] != NULL)
            delete (CBuffer*)buffers.item(i);
    for(int i = 0; i < sockets.count; i++)
        if(sockets[i] != NULL)
            delete (CSocket*)sockets.item(i);
    for(int i = 0; i < files.count; i ++)
        if(files[i] != NULL)
            CTools::BinClose((HANDLE)files.item(i));
    return 1;
}

#endif // DLL_H_INCLUDED


Was This Post Helpful? 0
  • +
  • -

#7 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Consequences of Inline Methods

Posted 28 April 2009 - 09:21 AM

The only file that includes the header file with implementations is the "Engine.h" file.

Engine.h is included by Headers.h

main.cpp includes Headers.h

EDIT:

Well, I've moved the implementation and received this error:

Error said:

obj\Debug\Engine.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2497|multiple definition of `_buffers'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
obj\Debug\Engine.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2498|multiple definition of `_sockets'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
obj\Debug\Engine.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2499|multiple definition of `_files'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
obj\Debug\main.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2497|multiple definition of `_buffers'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
obj\Debug\main.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2498|multiple definition of `_sockets'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
obj\Debug\main.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale_facets.tcc|2499|multiple definition of `_files'|
obj\Debug\39DLL\39DLL.o:C:\Users\Barroga Kids\Desktop\Project Kali\39DLL\39DLL.cpp|4|first defined here|
||=== Build finished: 12 errors, 0 warnings ===|

This post has been edited by e_barroga: 28 April 2009 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

#8 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Consequences of Inline Methods

Posted 28 April 2009 - 09:21 PM

Any help?
Was This Post Helpful? 0
  • +
  • -

#9 Plus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 41
  • View blog
  • Posts: 414
  • Joined: 24-November 08

Re: Consequences of Inline Methods

Posted 29 April 2009 - 12:37 AM

how can i start ...

first of all, it's obvious that you're using Code Blocks with MinGW compiler ...

next, you should use more ( ... ) for more detailed expressions ...

third, why using double when everything in your program asks for int !

finally, why don't you try another compiler or code IDE editor ...

and about "inline", only "inline" your own functions or ones you can reach, DON'T INLINE SYSTEM FUNCTIONS !

This post has been edited by Plus: 29 April 2009 - 12:39 AM

Was This Post Helpful? 0
  • +
  • -

#10 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: Consequences of Inline Methods

Posted 29 April 2009 - 05:04 AM

Just wondering.

What are the includes in the file holding main()?

Any duplication with the includes in the header files?
Was This Post Helpful? 0
  • +
  • -

#11 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Consequences of Inline Methods

Posted 29 April 2009 - 12:49 PM

janotte, the only thing included in my "main.cpp" file is: #include "Headers.h"


View PostPlus, on 28 Apr, 2009 - 11:37 PM, said:

how can i start ...

first of all, it's obvious that you're using Code Blocks with MinGW compiler ...

next, you should use more ( ... ) for more detailed expressions ...

third, why using double when everything in your program asks for int !

finally, why don't you try another compiler or code IDE editor ...

and about "inline", only "inline" your own functions or ones you can reach, DON'T INLINE SYSTEM FUNCTIONS !


The networking library was not written by me. The reason that they are doubles is because it is originally a networking DLL to extend functionality to a software called: "Game Maker".

Everything defined in the "Functions.h" file (the one with the #ifndef DLL_H_INCLUDED guards) is used to get the DLL to work with Game Maker.

Functions.h
#ifndef DLL_H_INCLUDED
#define DLL_H_INCLUDED

#include "includes.h"
#include "tools.h"
#include "socket.h"
#include "buffer.h"
#include "list.h"

( ... )

#endif // DLL_H_INCLUDED



Engine.h
#ifndef ENGINE_H_INCLUDED
#define ENGINE_H_INCLUDED

#include "Functions.h"

//Engine Class Declaration
( ... )

#endif //ENGINE_H_INCLUDED



Engine.cpp
#include "Engine.h"

//Engine Class Implementation
( ... )




Headers.h
#ifndef HEADERS_H_INCLUDED
#define HEADERS_H_INCLUDED

#include <iostream>
#include <vector>
#include <fstream>

#include "Engine.h"

#endif //HEADERS_H_INCLUDED



main.cpp
#include "Headers.h"

int main() {
	
	Engine Game();

	cin.get();	

	return 0;
	
}




All the files that "Functions.h" includes are pretty much classes to provide networking support using WinSock. They're implementations are separated from their declarations.

The "Functions.h" file is a bunch of functions that sort of performs encapsulation. It simply hides the process of dealing with objects.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1