Main.cpp
#include "Header.h"
SolveSE(1, 2, 3);
Header.h
struct Solution;
Solution SolveSE(double ax, double bx, double c);
SSE.cpp
#include "Header.h"
struct Solution
{
size_t count;
double *roots;
};
Solution SolveSE(double ax, double bx, double c)
{
if (fabs(ax)<1e-5)
{
throw std::invalid_argument("a should not be a zero");
}
double Discriminant = bx - 4 * ax * c;
if (Discriminant > 0)
{
double x1 = -bx + sqrt(Discriminant) / 2 * ax;
double x2 = -bx - sqrt(Discriminant) / 2 * ax;
double roots[] = { x1, x2 };
return { 2, roots };
}
if (Discriminant == 0)
{
double x1 = -bx + sqrt(Discriminant) / 2 * ax;
double roots[] = { x1};
return { 1, roots };
}
if (Discriminant < 0)
{
return { 0};
}
return {};
}
Error from Visual Studio:
Severity Code Description Project File Line Suppression State Error C2027 use of undefined type 'Solution' SolveSquareEquation c:\users\dima\documents\visual studio 2017\projects\solvesquareequation\solvesquareequation\main.cpp 8
And floating tip say, that return type 'Solution' is incompleate.
There someothing with my function implementation?
test.cpp
TEST_METHOD(TestSSE)
{
Assert::AreEqual<Solution>(SolveSE(1,3,-4), {2, {4, 1}})
}
struct Solutiondefinition is only visible inSSE.cpp, you should move it to header.struct Solution { size_t count; double *roots;};. OtherwiseSolutiontype will be incomplete and cause errors when function is invoked in translation units other thanSSE.cpp. PS you are also missing some includes, for examplecstdintforsize_tandcmathforsqrt.