Error C2027 Use Of Undefined Type Forward Declaration
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings error c2027 use of undefined type c++ and policies of this site About Us Learn more about Stack Overflow use of undefined type class c++ the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Error Forward Declaration Of Class
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it
Error Invalid Use Of Incomplete Type Class
only takes a minute: Sign up confused on forward declarations up vote 2 down vote favorite #pragma once #include "Player.h" class Player; //class SmallHealth; const int kNumOfCards = 3; //for Player class also const int kCardLimit = 3; class Cards { private: protected: int turnsInEffect; Player *owner; public: Cards() {turnsInEffect = 1;} void AssignOwner(Player &player) { owner = &player; } error invalid use of incomplete type forward declaration virtual void PlayCard() {} virtual ~Cards(void) {} }; class SmallHealth : public Cards { public: void PlayCard() { turnsInEffect = 1; owner->SetHealth(owner->GetHealth() + 5); //check if health goes over if(owner->GetHealth() > owner->GetHealthLimit()) { owner->SetHealth(owner->GetHealthLimit()); } turnsInEffect--; } }; I thought by declaring class Player I wouldn't get these errors: error C2027: use of undefined type 'Player see declaration of 'Player' error C2227: left of '->SetHealth' must point to ... Checking on error 2027, seems I have to explicitly have the whole class before the Cards class, but I thought the forward class declaration would make it unnecessary. How I have it set up is that Cards class is created and assigned a subclass by the Player class and stored in the Player class. The subclasses that inherit the Cards class will call upon the functions of the Player class. I'm having a tough time making sure the 2 classes identify each others classes. c++ forward-declaration share|improve this question edited May 27 '15 at 17:48 Jonathan Leffler 438k61509822 asked Nov 22 '11 at 23:21 user998797 1814 W
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Error C2027 Use Of Undefined Type Template
this site About Us Learn more about Stack Overflow the company Business Learn c++ use of undefined type forward declaration more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question forward declaration of class c++ x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/8235324/confused-on-forward-declarations Use of undefined type [duplicate] up vote 6 down vote favorite This question already has an answer here: When can I use a forward declaration? 12 answers #include
Class "A" have a pointer to the original "creator object" of class "B" http://www.cplusplus.com/forum/beginner/31788/ so they can access the original instance. The file looks a bit like this: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class B; class A { public: A() : _p(NULL) {} A(B* http://www.dreamincode.net/forums/topic/286571-error-c2027-use-of-undefined-type-channel/ p) : _p(p) {} void TestFunc(int val) { _p->SetVal(val); } private: B* _p; }; class B { public: B(int v) : val(v) { s =A(this); } void use of SetVal(int v) { val = v; } void TestFunc(int val) { s.TestFunc(val); } private: A s; int val; }; However this gives me a compile error: 1>X\main.cpp(9) : error C2027: use of undefined type 'B' 1> X\main.cpp(2) : see declaration of 'B' Causes/how to create this? Nov 19, 2010 at 2:02pm UTC filipe use of undefined (1165) _p->SetVal(val); You can't inline this just with a forward declaration. Remember, a forward declaration knows nothing about the class, it only allows you to use pointers or references, not methods. EDIT: -Objects of Class "A" have a pointer to the original "creator object" of class "B" so they can access the original instance. Also notice this shouldn't be necessary at all. If A has a pointer to an object of type B, A should know how to manipulate B, but B shouldn't know anything about A. Last edited on Nov 19, 2010 at 2:04pm UTC Nov 19, 2010 at 2:15pm UTC paul23 (22) @filipe: I'm afraid I don't fully understand what you are saying there (in the edit). As you can see in the "example": "A" can manipulate "B", however "A" ought to be accessed only from "B".. Let's put it more into english words: Suppose I have a "Car" (object "B").. That care has a
Pages) 1 2 → New Topic/Question Reply 21 Replies - 5610 Views - Last Post: 23 July 2012 - 03:06 PM Rate Topic: #1 Sebi13 New D.I.C Head Reputation: 0 Posts: 45 Joined: 22-September 11 error C2027: use of undefined type 'Channel' Posted 22 July 2012 - 07:24 AM Hello, I'm having trouble compiling an application(VC++2008). I'm getting the undefined type error in one of my classes. I have two files channel.h and link.h: // channel.h class Channel { private: bool marked; ... public: ... void mark(void) { marked = true; } void unmark(void) { marked = false; } bool is_marked(void) const { return marked; } ... }; And link.h // link.h #include "nodes.h" // <= includes "channel.h" class Channel; class Link { protected: Channel *src, *dst; ... public: ... void mark_src(void) { src->mark(); } //<= error C2027: use of undefined type 'Channel' void unmark_src(void) { src->unmark(); } // <= error C2227: left of '->mark' must point to class/struct type bool is_marked_src(void) const { return src->is_marked(); } void mark_dst(void) { dst->mark(); } void unmark_dst(void) { dst->unmark(); } bool is_marked_dst(void) const { return dst->is_marked(); } ... }; I have include guards in every header file(each header file is named differently). I know this means that the compiler does not know the type 'Channel' at compile time but is there a way not to merge the files channel.h and link.h together? I don't want the implementation of the mark methods in the same .cpp file either. Many thanks in advance. Sebi Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: error C2027: use of undefined type 'Channel' #2 jimblumberg Reputation: 4990 Posts: 15,622 Joined: 25-December 09 Re: error C2027: use of undefined type 'Channel' Posted 22 July 2012 - 07:27 AM Please post the complete error message exactly as it appears in your development environment. Jim Was This Post Helpful? 0 Back to top MultiQuote Quote + Reply #3 Sebi13 New D.I.C Head Reputation: 0 Posts: 45 Joined: 22-September 11 Re: error C2027: use of undefined type 'Channel' Posted 22 July 2012 - 07:28 AM jimblumberg, on 22 July 2012 - 07:27 AM, said:Please post the complete error message exactly as it appears in your development environment. Jim The errors are: 1>c:\reserach\complex_networ