c ++ - 在头文件中使用时无法识别struct

Rot*_*ese 0 c++ struct

我有一个名为的文件:内FeedbackCircuitVariables.h有以下内容:

#pragma once

struct FeedbackCircuitVariables {
    // Unknown values (the ones which will be calculated).
    float m_Ic, m_Ib;
    float m_Vce;

    // Known values (the ones asked to user through keyboard).
    float m_Rc, m_Rb, m_Re;
    float m_Vbe, m_Vcc;
};
Run Code Online (Sandbox Code Playgroud)

还有一节课FeedbackCircuit.h:

#pragma once

#include "FeedbackCircuitVariables.h"

class FeedbackCircuit {
private:
    FeedbackCircuitVariables *m_pVariables;
public:
    FeedbackCircuit(const FeedbackCircuitVariables *variables);
};
Run Code Online (Sandbox Code Playgroud)

这是该类的定义:

#include "FeeedbackCircuit.h"

FeedbackCircuit(const FeedbackCircuitVariables *variables) {

}
Run Code Online (Sandbox Code Playgroud)

但是在类的头部内,编译器说FeedbackCircuitVariables不是类型名称.

我究竟做错了什么?

Dre*_*ann 5

您的构造函数语法错误.

更改:

   FeedbackCircuit(const FeedbackCircuitVariables *variables)
Run Code Online (Sandbox Code Playgroud)

至:

   FeedbackCircuit::FeedbackCircuit(const FeedbackCircuitVariables *variables)
// ^^^^^^^^^^^^^^^^^ This is the scope of the thing you're defining.
Run Code Online (Sandbox Code Playgroud)

那么你的代码应该构建.