Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tom64

Pages: 1 2 [3] 4
31
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 09:10:54 am »
Quote
Also Lib2 is doing it wrong. If it's one of your library, you should change it and let it use its own namespace.

AAHAHAAARRRGGHH IM SO CONFUSE.

But lib2 is an example of someone elses library that has a function. lib1 is an example of my library where I force a namespace... ????????????????????????

The point of this topic was to ask how to make a function that has the same name and use it without namespace::

32
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 09:08:49 am »
eXpl0it3r, if that code works, then can't I just do 'using namespace exp' which would answer the very question everyone was telling me I couldn't do...???

33
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 09:05:32 am »
Why am I getting errors.. Here's the code I'm using. I have two simple test libraries included: lib1.h and lib2.h

main.cpp
#include "lib1.h"
#include "lib2.h"
#include <iostream>

using namespace LIB1;

int main(){
        std::cout << func() << std::endl;
        return 0;
}

lib1.h
#pragma once

namespace LIB1{
        int func(void);
}

lib1.cpp
#include "lib1.h"

namespace LIB1{
        int func(){
                return 1;
        }
}

lib2.h
#pragma once

int func(void);
 

lib2.cpp
#include "lib2.h"

int func(){
        return 0;
}
 

34
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 08:56:04 am »
Ok.. so how do I attach namespaces to my own functions if it has an identical name?

my lib file
namespace myLib{
        // My declarations/definitions here
}

main.cpp

using namespace myLib

int main(){
       func()
}

??

I can't get it to work..

Why do I have to use myLib:: if I have 'using namespace' added? It would solve most/all of my problems if I did namespace my functions but could just 'using' it...

35
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 08:44:08 am »
Quote
So you would prefer to type:
Yes.

So you would prefer:
xaxis = TankHeroMemberLibraryIsAwsome::round()..  ;D

36
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 08:40:16 am »
So you would prefer to type:

xaxis = hsuxz::round(i)+hsuxz::otherFunc();

than

xaxis = round(i)+otherFunc();

??

Quote
Also, for round, are you including <cmath> instead of <math.h>? <cmath> adds the stuff to the std:: namespace.
No, it's just an example. I just want to know how to deal with this problem when I face it, because I know I will be writing lots of function names and I have OCD when it comes to naming things... I don't like the fact that other peoples libraries are telling me how (not) to name my functions...

37
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 08:26:07 am »
Surely if I can do that I should be technically possible to do it they other way around though?

What if someone wrote a ton a code which worked fine, but then when added a library all of a sudden it conflicted with everything? Surely they wouldn't start re-writing/editing all of their ton of code.. But rather, just simply force a namespace on the newly added library (for certain conflicting functions) when used in their main .cpp?

38
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 08:19:28 am »
Quote
What is the name of the function, and in which library is it?
I'm just asking from a general point of view.

Quote
You should really use a namespace for your own functions
Quote
Why? Namespaces are there to be used. And if you can't change the other library (you really can't), then do it right in your library at least.

Because in my main program I won't be using the external functions like 'round' I will be using my own 'round' function. It would be too tedious and messy to have to use myNamespace::round() for every single function from my library (since I plan on making lots of functions and using them often).

EDIT: I think it's kinda silly how C++ works. The more libraries you load the greater the chance of a conflict. They should have designed it so that you, the programmer of your own app/lib get to choose whatever names you want, and any external libs that are not yours should require a namespace if there's a conflict.

I come from other programming languages where I've learned not only the names of functions, but how they work. I want to replicate the writing style of the old language I'm used to in c++.

39
General / Re: C++: Two functions with same name dilema
« on: April 09, 2013, 07:30:49 am »
So for example, I want to do something like this:

My Library.h/.cpp:
namespace math{#include <math>}

int round(i){
     return math::round(i)+x;
}
 

main.cpp
using namespace "My Library.h";

int main(){
     // This is calling MY version of round() without needing a namespace
     cout << round(5);
}
 

40
General / C++: Two functions with same name dilema
« on: April 09, 2013, 07:24:23 am »
I want to make my own library that has functions. I'm very particular about function names, but heres the thing, some of the function names I want to use are already used in another library/file that is included in the program.

Thing is, I don't want to modify included libraries that are not mine or affect how they work (since I will need to use their version of the function too).

In a nutshell it's like this (example!):

External Library has a round() function (for rounding numbers).
My Library also has a round() function which USES the round() function from the external library (mine uses it, but works slightly differently)!

.. and then, in my main.cpp program, if I call round() I want it to know I'm referring to MY library (not the other 'External' library). And I don't want to have to refer to my functions using long/additional tags like:  myLibrary::round().

If I do use namespace tags etc, anywhere in my code, I'd rather it be for the External library functions. But remember, I don't want to edit their library or cause it to not work anymore (since I'm guessing their library (and maybe several other libraries also makes use of that functions without knowing of any changes/additions in namespaces!). Basically I don't want to screw all the other libraries up which aren't mine.

How can I overcome this??

Thanks in advance,
Tom

41
General / Re: Will clients need anything to run my EXEs?
« on: April 03, 2013, 09:05:16 am »
I'm using Visual Studio to write C++. I'm not really sure what .NET is, all I know is I don't want it. I'm not sure if VS automatically adds it to C++ exes or not.

42
(C++ question) I need to be able make a compiled code (like a .dll?) which other programmers can use on linux, win,, mac, etc.

The compiled code would simply do calculations and spit out an answer in memory.

I need it to have certain functions that they can easily call and understand (without actually seeing the source).

Does anyone know if this is possible and how?

Thanks in advance,
Tom.

43
Is it good practice (maximum efficient) to load data from a HDD file using the standard file loading function and a for loop? Or is there a faster way to load (especially if you're going to be loading large chunks of data in sequence from the HDD)?

44
General / Will clients need anything to run my EXEs?
« on: March 29, 2013, 01:03:46 pm »
If I make a program that uses SFML is there any chance it won't run because they don't have something installed? i.e. They won't need .NET, or OpenGL, etc.?

45
General / Parallel processing?
« on: March 27, 2013, 06:26:31 am »
Does anyone know of an easy way to get the computer to do something like: 4 completely separate tasks (assuming you have 4 cores), for each core?

i.e.

core_1( *task_1() )
core_2( *task_2() )
core_3( *task_3() )
core_4( *task_4() )

I know with parallel processing there are usually problems like collisions, but what if you give the different cores completely separate tasks with separate memory that won't collide?

Sincerely,
Tom

Pages: 1 2 [3] 4
anything