クラスを完全宣言に先立ってポインタまたは参照で参照できるように、クラスを「宣言する」ことができます。
class MyClass; // forward declaration
void fn1(MyClass* ptr); // legal
void fn2(MyClass* ptr) // legal
{
ptr->something; // illegal, definition of MyClass unknown
}
class A {
MyClass mc; // illegal, definition of MyClass unknown
};
class MyClass {
// ...
};
しかし、あなたの例では、あなたが次のことを書いた:
typedef struct testStructure
{
int data;
void *TestFunction(testStructure *tempStructValue)
} temp;
これはクラスを宣言し、testStructure
、その整数メンバーdata
とvoid*
ポインタを返すメンバ関数TestFunction
として。こののメンバー関数は、以前の無料の関数TestFunction
とは全く関係ありません。あなたの意図が何であるかは不明です。
例:彼らは他の方法で回避宣言されている場合
#include <iostream>
struct TestStructure;
void TestFunction(TestStructure* /*unused*/) {
std::cout << "Free TestFunction\n";
}
struct TestStructure {
int i;
void TestFunction(TestStructure* /*unused*/) {
std::cout << "TestStructure TestFunction\n";
}
void foo() {
std::cout << "From foo\n";
TestFunction(this);
}
};
int main() {
std::cout << "From main:\n";
TestFunction(nullptr);
TestStructure t;
t.foo();
}
http://ideone.com/1453GG
同じことが当てはまります。http://ideone.com/VDcJxe
名はスコープに基づいて解決されているためです。クラス/構造体のメンバ関数は、/ structを参照する前にクラス/構造体のスコープを参照します。私たちは、メンバ関数内から自由に関数を呼び出すしたい場合は、私たちのような「::」スコープ演算子を使用することができます。
void foo() {
::TestFunction(); // resolves from the global scope
}
参照:http://ideone.com/B51J4C(私は順番に必要とする関数を宣言転送することを選んだ注意私はそのクラスの宣言クラスを宣言している)。
これはCかC++ですか? – merlin2011
フォワード宣言。 – Jarod42
あなたの言語を正しく参照していることを確認してください。あなたはC++を使っているので、Cタグは使わず、 "C"とは言わないでください。彼らは異なるイディオムを持つ2つの異なる言語です。 – skrrgwasme