My static library functions are not working as I expect them to..

Azavier Allen 1 Reputation point
2022-01-15T03:27:56.97+00:00

So, I started to try to make my own library the other day with Visual Studio 2017, and I have been struggling.. I got it working, sorta, but one of my functions would return "-nand(ind)" instead of the fixed return value of "5.0" I put inside of the function.. that issue resolved itself, somehow, but more appeared after.. when I tried to add a second function to debug, with the same return value, it was just an overloaded function, it seemed to work properly.. except for the other one. instead of returning "5" like I specified for it to, it returns "1". Also, when you try to run both of the functions within the same program, it fails to compile.

Related code snippets:

mUtils.h (header file for my functions)

#pragma once

namespace mDay {
 class mUtils {
 public:
 static float map(float val, float minRA, float maxRA, float minRB, float maxRB);

 static float map(float val, float minR, float maxR);
 };
}

mUtils.cpp (source file for my functions)

#include "mUtils.h"

namespace mDay {
 float mUtils::map(float val, float minRA, float maxRA, float minRB, float maxRB) {
 return 5.0; // minRB + (maxRB - minRB) / (maxRA - minRA) * (val / minRA)
 }

 float mUtils::map(float val, float minR, float maxR) {
 return 5.0;
 }
}

mDay.h (header file to compile all of the classes in my library)

#pragma once

#include "mUtils.h"
#include "mDebug.h"

mainApp.cpp (the program I'm using to debug)

#include <iostream>
#include "mDay.h"

#define deb mDay::mDebug::
#define uti mDay::mUtils::

using namespace std;

int main()
{
 float dA = uti map(0, 1, 1);
 float dB = uti map(0, 1, 0, 1, 0);

 cout << dA << endl;
 cout << dB << endl;

 return 0;
}
Developer technologies C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. WayneAKing 4,931 Reputation points
    2022-01-15T09:09:48.857+00:00

    You haven't shown the code for mDebug.h so I built your
    sample without it. There were no build errors, and it shows
    5 from both cout lines.

    The results are the same for all x86 and x64 Debug and
    Release builds. Used VS 2017 Community version 15.9.41

    • Wayne

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.