forward-declaration

Forward declarations in C++ - when it's matter? [closed]

こ雲淡風輕ζ 提交于 2020-01-07 00:39:14
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I think it's a spirit of C++ - you don't pay for what you don't want ( you explicitly pay for what you need ): // a.h #include <iosfwd

Forward declarations in C++ - when it's matter? [closed]

有些话、适合烂在心里 提交于 2020-01-07 00:37:17
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I think it's a spirit of C++ - you don't pay for what you don't want ( you explicitly pay for what you need ): // a.h #include <iosfwd

A vector member is reset and unaccessible

寵の児 提交于 2020-01-06 05:33:05
问题 I have two projects, one basic client and a dynamic library. Here's what happens in the client: int main() { Scrutinizer scru; scru.Scrutinize(); return 0; } In the DLL, The Scrutinizer class is as such (__declspec(dllexport) and such omitted for Clarity) Header class ProcessesGenerator; class Scrutinizer { public: Scrutinizer(); ~Scrutinizer(); ProcessesGenerator *ProcGenerator void Scrutinize(); }; The forward declaration of ProcessesGenerator was 'mandatory' for me to avoid some kind of

Forward Declaration of Template Class (Visitor Design Pattern)

寵の児 提交于 2020-01-06 05:08:49
问题 I am trying to forward declare a templated class A<T> for use in a class Visitor . It would suffice for my purposes to declare the int instance A<int> of the class A . I have tried two approaches but both give different errors, and I don't know how to proceed. Here is a MWE of my error: namespace visitor{ class Visitor{ public: virtual void visit(nsp::A<int>*) = 0; }; } namespace nsp{ template <class T> class A{ A(); T t_attribute; void accept(visitor::Visitor*); }; void A<int>::accept

Forward Declaration of Template Class (Visitor Design Pattern)

≡放荡痞女 提交于 2020-01-06 05:08:28
问题 I am trying to forward declare a templated class A<T> for use in a class Visitor . It would suffice for my purposes to declare the int instance A<int> of the class A . I have tried two approaches but both give different errors, and I don't know how to proceed. Here is a MWE of my error: namespace visitor{ class Visitor{ public: virtual void visit(nsp::A<int>*) = 0; }; } namespace nsp{ template <class T> class A{ A(); T t_attribute; void accept(visitor::Visitor*); }; void A<int>::accept

Why is forward declaration of structure not working in my code? When can it be used in C?

旧城冷巷雨未停 提交于 2020-01-05 10:28:33
问题 Isn't forward declaration, whether for structures or functions, supposed to do what forward declaration is expected to do, ie, to let us use the structure or function before they are defined? Why is the forward declaration of a structure not working in my code? And the main thing that just misses me, is forward declaration of structures of any use in C at all? When is it used? Can you please give me a small C program example to illustrate this? My program gives the error error: storage size

Why are pointers to incomplete types allowed and not variables of incomplete types?

前提是你 提交于 2020-01-05 05:56:19
问题 Why is the following legal: typedef struct a aType; struct a { int x; aType *b; }; and the following illegal: void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; } I'm just curious as in each case it is forward referencing and as far as I know, at least for functions and variables, forward referencing is not legal. Also, would the answer for this be the same for C++ as well? 回答1: This of it this way: typedef struct a aType; struct a { int x; aType *b; };

Circular references in C++ in different files

末鹿安然 提交于 2020-01-04 07:28:11
问题 If i want a circular reference but in two different files in C++, how would I implement that? For example AUnit.h #inclue <BUnit.h> class AClass : public TObject { __published BClass * B; }; BUnit.h #include <AUnit.h> class BClass : public TObject { __published AClass *A; }; I can't make it in only one file with forward declarations. 回答1: I assume you're talking about circular dependencies . The answer is indeed to use a forward declaration, such as: AUnit.h #include <BUnit.h> class AClass :

Will the standard library of C++11 have forward declaration headers?

不问归期 提交于 2020-01-03 12:31:09
问题 In C++03 there are no <vectorfwd> -like files, while there is the <iosfwd> header. Will this change in the future? It could be valuable to reduce dependencies and for better modularity. UPDATE: I have received an answer from the language creator: " practically it's not possible to require this from all STL vendors ". 回答1: No, there are no new forward files, just the old <iosfwd> . The complete I/O-system is large compared to a vector, so the advantage would perhaps not be that significant. 来源

“Attempting to use the forward class 'Game' as superclass of 'MathGame'” in Cocos2d

六眼飞鱼酱① 提交于 2020-01-03 07:25:06
问题 I'm making a Cocos2d game for iphone, and I have my main game mode, Game , which inherits from CCLayer . I'm trying to make another game mode, MathGame , which inherits from Game , but when I try to compile, I get this error in MathGame.h : Attempting to use the forward class 'Game' as superclass of 'MathGame' I get the error even if the implementation and interface of MathGame are empty. And it only happens if I try to include MathGame.h in another file. Here's the code for the Game class: /