1

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}})
}
8
  • 1
    struct Solution definition is only visible in SSE.cpp, you should move it to header. Commented Sep 21, 2017 at 12:10
  • Please show real code, if you want real answers, instead of obviously fake code. Commented Sep 21, 2017 at 12:10
  • I have struct Solution; in Header.h Commented Sep 21, 2017 at 12:11
  • 1
    Its my real code. I start learning c++. Commented Sep 21, 2017 at 12:11
  • 1
    You have only forward declaration of struct there. But you need definition struct Solution { size_t count; double *roots;};. Otherwise Solution type will be incomplete and cause errors when function is invoked in translation units other than SSE.cpp. PS you are also missing some includes, for example cstdint for size_t and cmath for sqrt. Commented Sep 21, 2017 at 12:12

1 Answer 1

1

you should move struct to header file:

struct Solution
{
    size_t count;
    double *roots;
};
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but how i can get work Assert::AreEqual function with my type "Solution" or what i can do in this case? Severity Code Description Project File Line Suppression State Error (active) E0304 no instance of overloaded function "Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual" matches the argument list SolveQuadraticEquationUnitTest c:\Users\Dima\Documents\Visual Studio 2017\Projects\SolveSquareEquation\SolveQuadraticEquationUnitTest\unittest1.cpp 35
Severity Code Description Project File Line Suppression State Error C2664 'void Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual<Solution>(const T &,const T &,const wchar_t *,const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo *)': cannot convert argument 2 from 'initializer list' to 'const Solution &' SolveQuadraticEquationUnitTest c:\users\dima\documents\visual studio 2017\projects\solvesquareequation\solvequadraticequationunittest\unittest1.cpp 35
Any explanations about it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.