Her biri diğer sınıf türünde bir nesne içeren iki sınıf oluşturmak istiyorum. Bunu nasıl yapabilirim? Bunu yapamazsam, her sınıfın diğer sınıf tipine işaretçisi içermesi gibi bir çalışma var mı? Teşekkürler! İşte C++ içinde birbirini veri olarak kullanan iki sınıf nasıl oluşturulur?
Ben ne:Dosya: bar.h
#ifndef BAR_H
#define BAR_H
#include "foo.h"
class bar {
public:
foo getFoo();
protected:
foo f;
};
#endif
Dosya: foo.h
#ifndef FOO_H
#define FOO_H
#include "bar.h"
class foo {
public:
bar getBar();
protected:
bar b;
};
#endif
Dosya: main.cpp
#include "foo.h"
#include "bar.h"
int
main (int argc, char **argv)
{
foo myFoo;
bar myBar;
}
$ g ++ main.cpp
In file included from foo.h:3,
from main.cpp:1:
bar.h:6: error: ‘foo’ does not name a type
bar.h:8: error: ‘foo’ does not name a type
"foo bar foo ihtiyaçları bar ihtiyacı ihtiyacı var." lawl. = P – prolink007