Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;使用库的应用程序表示未检测到成员_C++_C++11 - Fatal编程技术网

C++ C++;使用库的应用程序表示未检测到成员

C++ C++;使用库的应用程序表示未检测到成员,c++,c++11,C++,C++11,所以,我有一个应用程序,在DOS选择一个数字样式中使用一组数学公式。所以我制作了一个静态库,目前我已经链接了它们,但是当我尝试使用一个函数时,它会说没有检测到成员。以下是我的代码(重要部分): //库头文件: namespace Library_ { static float min, max, n, rem, i, r, l, w, m, v, k, r1, r2, r3, r4, h, b, b1, b2, s, value, count = 0; static float f

所以,我有一个应用程序,在DOS选择一个数字样式中使用一组数学公式。所以我制作了一个静态库,目前我已经链接了它们,但是当我尝试使用一个函数时,它会说没有检测到成员。以下是我的代码(重要部分): //库头文件:

namespace Library_ {
static float min, max, n, rem, i, r, l, w, m, v, k, r1, r2, r3, r4, h, b,
       b1, b2, s, value, count = 0; static float f = 1;

static class Main
{
public:
    class Geometry_2Dimensional
    {
        static void rectangle();
        static void circle();
        static void ETGRadius();
        static void ETGSide();
    };

    class Geometry_3Dimensional
    {
        static void prismRectangle();
        static void prismTriangle();
        static void cylinder();
        static void sphere();
    };

    class Computing
    {
        static void rng();
        static void binary(int num);
    };

    class Number_Theory
    {
        static void average();
        static void primeCheck();
        static void primeFactors();
        static void factorial();
    };

    static void Error();
};
}
//库源文件:

include "CalculatorLib.h"
include <stdexcept>
include <iostream>
include <time.h>
include <math.h>
include <cstdlib>
include <conio.h>
using namespace std;

namespace Library_
{
void Main::Error()
{
    cout << "Not a valid option." << endl;
    system("PAUSE");
}

void Main::Geometry_2Dimensional::rectangle()
{
    cout << "Length: "; cin >> l;
    cout << "Width: "; cin >> w;
    cout << "Area: " << l * w << "\nPerimeter: " << (2 * l) + (2 * w) << 
endl;
    system("PAUSE");
}
void Main::Geometry_2Dimensional::circle()
{
    cout << "Radius: "; cin >> r;
    cout << "Area: " << r * 3.14 * r << "\nCircumference: " << r * 6.28 << 
endl;
    system("PAUSE");
}
void Main::Geometry_2Dimensional::ETGRadius()
{
    cout << "Integer part: "; cin >> r1;
    cout << "Radicant: "; cin >> r2;
    r3 = sqrt(r2);
    m = (sqrt(3) / 3);
    if (r2 == 3)
    {
        n = r1 * 3;
        cout << "The side length of the triangle is: " << n << endl;
        v = n / 2;
        k = sqrt((n * n) - (v * v));
        cout << "The area of the triangle is: " << (k * n) / 2 << endl;
        system("PAUSE");
    }
    else
    {
        r4 = r3 * r1;
        n = r4 / m;
        cout << "The side length of the triangle is: " << n << endl;
        v = n / 2;
        k = sqrt((n*n) - (v*v));
        cout << "The area of the triangle is: " << (k * n) / 2 << endl;
        system("PAUSE");
    }
}
void Main::Geometry_2Dimensional::ETGSide()
{
    cout << "Enter the side length: "; cin >> s;
    r = (s / 3) * sqrt(3);
    cout << "The radius of the inner circle is: " << r << endl;
    v = s / 2;
    k = sqrt((s*s) - (v*v));
    n = k * s;
    cout << "The area of the triangle is: " << n / 2 << endl;
    system("PAUSE");
}

void Main::Geometry_3Dimensional::prismRectangle()
{
    cout << "Length: "; cin >> l;
    cout << "Width: "; cin >> w;
    cout << "Height: "; cin >> h;
    cout << "Area: " << l*w*h << "\nSurface Area: " << (2 * (l*w)) + (2 * 
(l*h)) + (2 * (h*w)) << endl;
    system("PAUSE");
}
void Main::Geometry_3Dimensional::sphere()
{
    cout << "Radius: "; cin >> r;
    cout << "Volume: " << 3.14 * (4 / 3) * r * r * r << "\nSurface Area: " 
<< 12.56 * r * r << endl;
    system("PAUSE");
}
void Main::Geometry_3Dimensional::cylinder()
{
    cout << "Radius: "; cin >> r;
    cout << "Height: "; cin >> h;
    cout << "Volume: " << 3.14 * r * r * h << "\nSurface Area: " << 6.28 * r  
* h * (r + h) << endl;
    system("PAUSE");
}
void Main::Geometry_3Dimensional::prismTriangle()
{
    cout << "Base of the base: "; cin >> b;
    cout << "Height: "; cin >> h;
    cout << "Length: "; cin >> l;
    cout << "Other sides of base: " << "\nFirst other side: "; cin >> b1;
    cout << "Second other side: "; cin >> b2;
    cout << "Volume: " << h * b * l << "\nSurface Area: " << (2 * b * h) +  
 ((b + b1 + b2) * l) << endl;
    system("PAUSE");
}

void Main::Computing::rng()
{
    cout << "Enter the minimum: "; cin >> min;
    cout << "Enter the maximumL "; cin >> max;
    cout << "Enter the number of generations: "; cin >> n;
    int range = max - min + 1;
    unsigned first = time(NULL);
    srand(first);
    for (i = 0; i < n; i++)
    {
        r = rand() / 100 % range + min;
        cout << r << " ";
    }
    cout << endl;
    system("PAUSE");
}
void Main::Computing::binary(int num)
{
    if (num <= 1)
    {
        cout << num;
        return;
    }
    rem = num % 2;
    binary(num / 2);
    cout << rem;
}

void Main::Number_Theory::average()
{
    cout << "Enter the number of values: "; cin >> n;
    float average(0);
    for (int i = 0; i < n; ++i)
    {
        cin >> value;
        average += value;
    }
    average /= n;
    cout << "Average is " << average << endl;
    system("PAUSE");
}
void Main::Number_Theory::factorial()
{
    cout << "Enter the number: "; cin >> n;
    for (int a = 1; a <= n; a++)
    {
        f *= a;
    }
    cout << "The factorial is: " << f << endl;
    system("PAUSE");
}
void Main::Number_Theory::primeCheck()
{
    cout << "Enter the number: "; cin >> n;
    int count = 0;
    for (int a = 1; a <= n; a++)
    {
        if (fmod(n, a) == 0)
        {
            count++;
        }
    }
    if (count == 2)
    {
        cout << "The number " << n << " is prime!" << endl;
        system("PAUSE");
    }
    else
    {
        cout << "The number " << n << " is not prime." << endl;
        system("PAUSE");
    }
}
void Main::Number_Theory::primeFactors()
{
    cout << "Enter the number: "; cin >> n;
    while (fmod(n, 2) == 0)
    {
        cout << "2, ";
        n /= 2;
    }

    for (int i = 3; i <= sqrt(n); i += 2)
    {
        while (fmod(n, 1) == 0)
        {
            cout << i << ", ";
            n /= i;
        }
    }

    if (n > 2)
    {
        cout << n << ", ";
    }
}
}
包括“CalculatorLib.h”
包括
包括
包括
包括
包括
包括
使用名称空间std;
名称空间库_
{
void Main::Error()
{
库特w;

cout您在这里犯了太多错误,很难知道从哪里开始,像使用名称空间一样使用类,使用全局变量,在库代码中进行输入和输出,不使用函数参数和函数返回,不适当地使用static等等。此外,由于您没有显示trong>如何调用函数

我可以回答一个问题,“何时使用静态”。根据您的经验,答案是永远不要使用静态。您必须先学习基本知识

忘记类。忘记名称空间,忘记全局变量,首先学习如何编写函数,如何使用局部变量,如何向函数传递值和从函数返回值

例如,以下是完全可以接受的初学者代码

void Geometry_2Dimensional_ETGRadius(float r1, float r2, float& n, float& k)
{
    float r3 = sqrt(r2);
    float m = (sqrt(3) / 3);
    if (r2 == 3)
    {
        n = r1 * 3;
        float v = n / 2;
        k = sqrt((n * n) - (v * v));
    }
    else
    {
        float r4 = r3 * r1;
        n = r4 / m;
        float v = n / 2;
        k = sqrt((n*n) - (v*v));
    }
}

int main()
{
    float r1, r2, n, k;
    cout << "Integer part: "; cin >> r1;
    cout << "Radicant: "; cin >> r2;
    Geometry_2Dimensional_ETGRadius(r1, r2, n, k);
    cout << "The side length of the triangle is: " << n << endl;
    cout << "The area of the triangle is: " << (k * n) / 2 << endl;
    system("PAUSE");
}
void Geometry\u 2Dimensional\u ETGRadius(浮点r1、浮点r2、浮点n、浮点k)
{
浮点数r3=sqrt(r2);
浮动m=(sqrt(3)/3);
如果(r2==3)
{
n=r1*3;
浮点数v=n/2;
k=sqrt((n*n)-(v*v));
}
其他的
{
浮点数r4=r3*r1;
n=r4/m;
浮点数v=n/2;
k=sqrt((n*n)-(v*v));
}
}
int main()
{
浮球r1,r2,n,k;
cout>r1;
cout>r2;
几何二维梯度(r1,r2,n,k);

你能不能包括你的main.cpp文件和链接器标志以及…?@paykoob链接器标志,这意味着所有的包含和使用?我正在使用stdafx.h,所以这里有所有的内容:#包括“targetver.h”#包括“Library\CalculatorLib.h”#包括使用namespace std;使用namespace Library#;但是我想要创建一个库的全部原因是,我的主应用程序需要更少的代码,因为所有函数和变量都在库中,我的主函数只关注在控制台应用程序中导航和使用函数。这些函数不会然后在流式处理中处理这些变量,因此类似于案例1:Main::Geometry_2Dimensional::rectangle();但当我做Main::Geometry_2Dimensional::时,它说不包括任何成员,你可以将普通函数放入库中。你不需要名称空间或类来创建库。你试图一次做太多事情,却不了解你想做什么。你试图编写的代码即使对于有经验的程序来说也不是好代码rammer。你必须先学习基础知识。我知道有更简单的方法可以做到这一点,它只是一种编码OCD,一切都必须组织起来。