error C2027: use of undefined type 'Channel'

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 2524 Views - Last Post: 23 July 2012 - 03:06 PM Rate Topic: -----

#1 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • 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
  • +

Replies To: error C2027: use of undefined type 'Channel'

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • 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
  • +
  • -

#3 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 07:28 AM

View Postjimblumberg, 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_networks\noc_sim_mod_vc\link.h(46) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(46) : error C2227: left of '->mark' must point to class/struct/union/generic type
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(47) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(47) : error C2227: left of '->unmark' must point to class/struct/union/generic type
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(48) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(48) : error C2227: left of '->is_marked' must point to class/struct/union/generic type
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(50) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(50) : error C2227: left of '->mark' must point to class/struct/union/generic type
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(51) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(51) : error C2227: left of '->unmark' must point to class/struct/union/generic type
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(52) : error C2027: use of undefined type 'Channel'
1> c:\reserach\complex_networks\noc_sim_mod_vc\link.h(6) : see declaration of 'Channel'
1>c:\reserach\complex_networks\noc_sim_mod_vc\link.h(52) : error C2227: left of '->is_marked' must point to class/struct/union/generic type

The errors appear only at the mark methods that are within the link.h file.

This post has been edited by Sebi13: 22 July 2012 - 07:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 07:42 AM

Have you actually tried including the header file instead of trying to forward declare you Channel class?

And you should never rely on another header to include a required header. I you use something that requires a header always include that header.

Other than that you will need to show the actual lines where the compiler is complaining about. For example the first error is on line 46 of your link.h header file.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:01 AM

View Postjimblumberg, on 22 July 2012 - 07:42 AM, said:

Have you actually tried including the header file instead of trying to forward declare you Channel class?

And you should never rely on another header to include a required header. I you use something that requires a header always include that header.

Other than that you will need to show the actual lines where the compiler is complaining about. For example the first error is on line 46 of your link.h header file.

Jim


I've tried that but with no success. Here are some of the variations I tried:
Forward declaration:
#ifndef LINK_H
#define LINK_H

#include "nodes.h"

class Channel;
class Port;
class Timer;
class Packet;
class Flit;
class Buffer;



Forward declaration with include file:
#ifndef LINK_H
#define LINK_H

#include "nodes.h"
#include "channel.h"

class Channel;
class Port;
class Timer;
class Packet;
class Flit;
class Buffer;



No forward declaration; include file only:
#ifndef LINK_H
#define LINK_H

#include "nodes.h"
#include "channel.h"

class Port;
class Timer;
class Packet;
class Flit;
class Buffer;



Both forward declaration and include file:
#ifndef LINK_H
#define LINK_H

#include "nodes.h"
#include "channel.h"

class Channel;
class Port;
class Timer;
class Packet;
class Flit;
class Buffer;



Here is the listing of the link.h file:
#include "nodes.h"
#include "channel.h"

class Port;
class Timer;
class Packet;
class Flit;
class Buffer;

class Link {
protected:
        Channel *src, *dst;
	int link_id;  // an identifier for our link(we will need one when we have multiple links in our link vector
	unsigned sent_flits;
	unsigned number_of_flits;       // used to keep track of the flits (in the source channel) so that we know when to call
						       // the send() method of a link with this source channel(when flits_per_packet = 1 we can't call send on each link of each arbiter of each c.c. we only call send on the link when we have lesser flits in the source channel at the end of the c.c. than at the beginning meaning that other links have sent flits to it)
	bool _good_to_go;
	Packet *rec_pkt;
	Flit *temp_flit;

	int send_delay;
	int k_clks;

public:
	Link(int link_id, int send_delay);
	~Link(void);

	void set_link_ends(Channel *src, Channel *dst);

	int send_src_dst(Timer *t);			// the source sends a flit to the destination in a clock cycle
									// send returns -1 if we have nothing to send(NULL flit) else 1 (we have a flit to send)
	int send_src_dst_and_unmark(Timer *t);  // umarks flits as processed when they pass from one node to another
	int send_dst_src(Timer *t);
	int send_dst_src_and_unmark(Timer *t);

	int get_link_id(void) const { return link_id; }
	Channel* get_src(void) const { return src; }
	Channel* get_dst(void) const { return dst; }

	bool fill_src(Flit *f, Timer *t);  // add flits to the source channel
	bool fill_dst(Flit *f, Timer *t);  // add flits to the destination channel of the link

	void mark_src(void) { src->mark(); }
	void unmark_src(void) { src->unmark(); }
	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(); }

	void good_to_go(void) { _good_to_go = true; }
	void not_good_to_go(void) { _good_to_go = false; }
	bool is_good_to_go(void) const { return _good_to_go; }

	Flit* peek_last_srcflit(void) const;
	Flit* peek_last_dstflit(void) const;

	Flit* peek_src_flit(void);
	Flit* get_src_flit(Timer *t);
	
	Packet *get_receiving_packet(void) const { return rec_pkt; }
};

#endif



One question: do I need to #include "channel.h" in the link.cpp file too?

Sebi
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:24 AM

What line in the above link.h corresponds to the error messages you posted earlier?

Also where do you allocate memory for your Channel pointers used in the Link class?

Posting the smallest complete program that illustrates your problem would probably help.

Jim

This post has been edited by jimblumberg: 22 July 2012 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

#7 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:34 AM

View Postjimblumberg, on 22 July 2012 - 08:24 AM, said:

What line in the above link.h corresponds to the error messages you posted earlier?

Also where do you allocate memory for your Channel pointers used in the Link class?

Posting the smallest complete program that illustrates your problem would probably help.

Jim


Starting from line 47 int the listing:
43 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type
44 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type
45 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type

47 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type
48 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type
49 <= error C2027: use of undefined type 'Channel'
<= error C2227: left of '->mark' must point to class/struct/union/generic type

Basically everything that deals with a 'Channel' object.
src and dst are set after calling a procedure:
void set_link_ends(Channel *src, Channel *dst) 
{
 this->src = src;
 this->dst = dst;
}



I use setters because link changes during runtime.

Sebi

This post has been edited by Sebi13: 22 July 2012 - 08:35 AM

Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:43 AM

And how are you calling set_link_ends()? Show how you are allocating memory for these pointers.

Jim
Was This Post Helpful? 0
  • +
  • -

#9 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:52 AM

View Postjimblumberg, on 22 July 2012 - 08:43 AM, said:

And how are you calling set_link_ends()? Show how you are allocating memory for these pointers.

Jim


I use the sequence:
for(unsigned i = 0; i < src_chans.size(); i++) // create links between virtual channels (sources & destinations)
	{
		// add a vacant link(we set the channels later on by arbitrating the requests);
		Link *ptemp_link = new Link(k++, IN_NODE_SEND_DELAY);
		ptemp_link->set_link_ends(src_chans[i], dst_chans[i]);  // <= channels are being set here
		links.push_back(ptemp_link);
	}



to set my channels. They are not NULL/invalidated when set_link_ends() is being called. Should I write a separate constructor for Link:
Link::Link(int link_id, int send_delay, Channel *src, Channel *dst);


which is guaranteed to set the channels before the mark methods are called?

Sebi
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:54 AM

How were src_chans and dst_chans defined?

Jim
Was This Post Helpful? 0
  • +
  • -

#11 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 08:58 AM

View Postjimblumberg, on 22 July 2012 - 08:54 AM, said:

How were src_chans and dst_chans defined?

Jim


They are vectors of channels:
vector<Channel*> src_chans;   // the arbiter pairs channels according to their status(free or not)
vector<Channel*> dst_chans;



Sebi
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 09:06 AM

And where are you actually allocating memory for those pointers? You must somewhere actually assign memory for those uninitialized pointers.

Jim
Was This Post Helpful? 0
  • +
  • -

#13 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 09:37 AM

View Postjimblumberg, on 22 July 2012 - 09:06 AM, said:

And where are you actually allocating memory for those pointers? You must somewhere actually assign memory for those uninitialized pointers.

Jim


I have two other classes InPort and OutPort which deal with the channel creation:
Port::Port(unsigned p_number, unsigned size, unsigned buffer_size, Node *src, Node *dst)
{
  assert (p_number >= 0 && size >= 0);
  assert (src != NULL && dst != NULL);

  this->currentp_number = p_number;
  this->size = size;
  this->buffer_size = buffer_size;

  this->src = src;
  this->dst = dst;

  direction = dst->get_id();

  channels.clear();

  for(unsigned i = 0; i < size; i++)
  {
	Buffer *temp_buffer = new Buffer(buffer_size);

	Channel *temp_chan = new Channel(i, p_number, src, dst);;

	temp_chan->bind_buffer(temp_buffer);

	channels.push_back(temp_chan);
  }
}



channels is a vector which holds channels either belonging to an InPort or OutPort.

Sebi
Was This Post Helpful? 0
  • +
  • -

#14 jimblumberg  Icon User is offline

  • member icon


Reputation: 3848
  • View blog
  • Posts: 11,775
  • Joined: 25-December 09

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 09:43 AM

This is the Port class. The previous errors are in the Link class. How are you allocating memory for the pointers used in the Link class?

Jim
Was This Post Helpful? 0
  • +
  • -

#15 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error C2027: use of undefined type 'Channel'

Posted 22 July 2012 - 09:55 AM

View Postjimblumberg, on 22 July 2012 - 09:43 AM, said:

This is the Port class. The previous errors are in the Link class. How are you allocating memory for the pointers used in the Link class?

Jim


Buffer *temp_buffer = new Buffer(buffer_size);
Channel *temp_chan = new Channel(i, p_number, src, dst);
temp_chan->bind_buffer(temp_buffer);



temp_chan is basically the newly allocated object. It is of type 'Channel' and I use two such objects to set the src and dst objects declared in the Link class via the method:
void Link::set_link_ends(Channel *src, Channel *dst)
{
	assert (src != NULL && dst != NULL);

	this->src = src;
	this->dst = dst;
}



in the Link class. The compiler only complains when I am trying to use src and dst declared in the Link class.

bool is_marked_src(void) const { return src->is_marked(); }



Apparently it "forgets" that src is of type 'Channel' and issues the errors:
error C2027: use of undefined type 'Channel' in link.h: see declaration of 'Channel'
error C2227: left of '->mark' must point to class/struct/union/generic type link.h
: error C2027: use of undefined type 'Channel'

Sebi

This post has been edited by Sebi13: 22 July 2012 - 09:56 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2