J
John Ratliff
I'm having issues with forward declarations and possibly member variables.
Can you declare a member variable and pass it parameters.
class x {
private:
y obj(this);
}
Is that valid? I'm getting a lot of problems, but it may not be due to
that. It may be due to the fact that the real X and Y require knowledge
of each other.
Here is a little example illustrating my problem. It would be a better
example if we put foo and bar in different files and included their
headers prior to the class def.
#include <iostream>
namespace myNS {
class bar;
class foo {
private:
bar b(this);
public:
void method() { std::cout << "foo"; }
void do() { b.method(); }
};
class bar {
private:
foo &f;
public:
bar(foo &f) : f(f) {}
void method() { f.method(); }
};
}
int main(int, char **) {
myNS::foo().do();
return 0;
}
This is clearly no good. Is it possible for foo to create a bar instance
b passing itself as a parameter?
Thanks,
--John Ratliff
Can you declare a member variable and pass it parameters.
class x {
private:
y obj(this);
}
Is that valid? I'm getting a lot of problems, but it may not be due to
that. It may be due to the fact that the real X and Y require knowledge
of each other.
Here is a little example illustrating my problem. It would be a better
example if we put foo and bar in different files and included their
headers prior to the class def.
#include <iostream>
namespace myNS {
class bar;
class foo {
private:
bar b(this);
public:
void method() { std::cout << "foo"; }
void do() { b.method(); }
};
class bar {
private:
foo &f;
public:
bar(foo &f) : f(f) {}
void method() { f.method(); }
};
}
int main(int, char **) {
myNS::foo().do();
return 0;
}
This is clearly no good. Is it possible for foo to create a bar instance
b passing itself as a parameter?
Thanks,
--John Ratliff