使用库的c++应用程序说没有检测到成员

C++ application using library says no members detected

本文关键字:检测 成员 应用程序 c++      更新时间:2023-10-16

所以,我有一个应用程序,在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 << ", ";
    }
}
}

然后是主源文件,它不能使用任何函数,因为智能感知说不包含任何成员。旁注:我包括头文件并使用命名空间Library_。如果这看起来很匆忙,那是因为我得走了。还有,除了解决这个问题,谁能告诉我什么时候不用静电?谢谢!

你在这里犯了很多错误,很难知道从哪里开始,使用类就好像它们是名称空间一样,使用全局变量,在库代码中进行输入和输出,不使用函数参数和函数返回,不恰当地使用静态等。也不可能回答你的问题,因为你没有显示如何你试图调用你的函数。

我可以回答一个问题,那就是"何时使用静态"。以你的经验水平,答案是永远不要使用静态。你得先学基础知识。

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

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

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");
}

查看仅在函数内使用的变量(r3, m等)如何在函数内声明。函数需要的值声明为函数的参数(r1, r2),函数返回的值声明为引用参数(nk)。