Discussion:
problem with header files
(too old to reply)
b***@yahoo.com
2006-05-24 20:37:35 UTC
Permalink
Hi

I am working with Visual studio 2005.
I have a problem here .The problem looks simple but yet could not solve
it,


CListCtrlOne.cpp
********************
#inlcude "tab1.h"
#include "MyListCTrlSomeX.h"

CTab1 *tab1;
CMyListCtrlSomeX *mylistCtrl;

No Problem until when I wanted to use like this

CListCtrl2.cpp
********************
#inlcude "tab1.h"
#include "MyListCTrlSomeY.h"

CTab1 *tab1;
CMyListCtrlSomeY *mylistCtrl;


The error is I am missing identifier before;
If I place in tab1.h in stdafx.h folder then replace from here,I get
the dialog ID is not getting recognised.
I can send the code if someone can help me.
Thanks
Bhargs
Jonathan Wood
2006-05-24 20:56:37 UTC
Permalink
I don't think you've provided enough details. Exactly which identifier is it
that is missing? And which header file defines it?
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Post by b***@yahoo.com
Hi
I am working with Visual studio 2005.
I have a problem here .The problem looks simple but yet could not solve
it,
CListCtrlOne.cpp
********************
#inlcude "tab1.h"
#include "MyListCTrlSomeX.h"
CTab1 *tab1;
CMyListCtrlSomeX *mylistCtrl;
No Problem until when I wanted to use like this
CListCtrl2.cpp
********************
#inlcude "tab1.h"
#include "MyListCTrlSomeY.h"
CTab1 *tab1;
CMyListCtrlSomeY *mylistCtrl;
The error is I am missing identifier before;
If I place in tab1.h in stdafx.h folder then replace from here,I get
the dialog ID is not getting recognised.
I can send the code if someone can help me.
Thanks
Bhargs
b***@yahoo.com
2006-05-24 22:02:55 UTC
Permalink
1>c:\samples\sample 1\mylistseriesresltsctrl.h(17) : error C2143:
syntax error : missing ';' before '*'
When I click F4 and it points to CTab1*
Jonathan Wood
2006-05-24 22:13:02 UTC
Permalink
Give us a clue please.

What is on line 17 of mylistseriesresultsctrl.h? Where is CTab1 defined?
Also, where is mylistseriesresltsctrl.h included--you didn't even mention
that in your original post.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Post by b***@yahoo.com
syntax error : missing ';' before '*'
When I click F4 and it points to CTab1*
b***@yahoo.com
2006-05-24 22:31:41 UTC
Permalink
ok sorry Jonathan
Here it is .
line 17 points to CTab1 * tab1;

CTab1 is derived from CDialog;

I am using Visual Studio 2005 and it does not ask for the file as I
created by using Project ->Create new class

code *************
#include"IconsListCtrl.h"
//#include "Tab1.h"

class CMyListSeriesResltsCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CMyListSeriesResltsCtrl)

public:
CMyListSeriesResltsCtrl();
virtual ~CMyListSeriesResltsCtrl();
void SetApply();
CIconsListCtrl *m_IconListCtrl; // new class
//CTab1 *tab1;
void SetIconToFill(CIconsListCtrl *pListCtrl ){
m_IconListCtrl = pListCtrl;

}
Ajay Kalra
2006-05-25 00:26:16 UTC
Permalink
Its still not clear what you are doing. CTab1 needs to forward declared or
its header file included in header file of CMyListSeriesResltsCtrl.

Something like:

class CTab1;

class CMyListSeriesResltsCtrl : public CListCtrl
{
....
CTab1 *tab1;
} ; // Note this semi colon. This needs to be there as well.


--
Ajay Kalra [MVP - VC++]
Post by b***@yahoo.com
ok sorry Jonathan
Here it is .
line 17 points to CTab1 * tab1;
CTab1 is derived from CDialog;
I am using Visual Studio 2005 and it does not ask for the file as I
created by using Project ->Create new class
code *************
#include"IconsListCtrl.h"
//#include "Tab1.h"
class CMyListSeriesResltsCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CMyListSeriesResltsCtrl)
CMyListSeriesResltsCtrl();
virtual ~CMyListSeriesResltsCtrl();
void SetApply();
CIconsListCtrl *m_IconListCtrl; // new class
//CTab1 *tab1;
void SetIconToFill(CIconsListCtrl *pListCtrl ){
m_IconListCtrl = pListCtrl;
}
Huang Leon
2006-05-25 08:40:02 UTC
Permalink
Yes, that's right.
Most rookies get confused on this problem.
I think you have given the key point to solve this question.
It should be in the FAQ of "Problems often met by freshman of VC++",
balabala...
--
Eternal Sunshine of the Spotless Mind......
Post by Ajay Kalra
Its still not clear what you are doing. CTab1 needs to forward declared or
its header file included in header file of CMyListSeriesResltsCtrl.
class CTab1;
class CMyListSeriesResltsCtrl : public CListCtrl
{
.....
CTab1 *tab1;
} ; // Note this semi colon. This needs to be there as well.
--
Ajay Kalra [MVP - VC++]
Post by b***@yahoo.com
ok sorry Jonathan
Here it is .
line 17 points to CTab1 * tab1;
CTab1 is derived from CDialog;
I am using Visual Studio 2005 and it does not ask for the file as I
created by using Project ->Create new class
code *************
#include"IconsListCtrl.h"
//#include "Tab1.h"
class CMyListSeriesResltsCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CMyListSeriesResltsCtrl)
CMyListSeriesResltsCtrl();
virtual ~CMyListSeriesResltsCtrl();
void SetApply();
CIconsListCtrl *m_IconListCtrl; // new class
//CTab1 *tab1;
void SetIconToFill(CIconsListCtrl *pListCtrl ){
m_IconListCtrl = pListCtrl;
}
Bhargs
2006-05-26 14:33:35 UTC
Permalink
Hi Ajay,

Thanks for your response.

Let me ask why and how this works.

Using the Class Wizard you subclass a control say ListControl -
CMyListControl and then add a variable type CMyListControl in the View
Class .

You see the #include files are automatically added to the view
class.Right!!

When you open this view header file you dont see forward declarations
of class CMyListControl.

I guess my point is clear.

thanks
Bhargavi
Ajay Kalra
2006-05-26 15:26:07 UTC
Permalink
This has nothing to do with what classwizard does or does not do. You
can do it that way as well.

Is your code working now? If yes, what did you do? Was it the missing
semi colon after the class definition that was the problem?

---
Ajay
Scott McPhillips [MVP]
2006-05-26 15:31:47 UTC
Permalink
Post by Bhargs
Hi Ajay,
Thanks for your response.
Let me ask why and how this works.
Using the Class Wizard you subclass a control say ListControl -
CMyListControl and then add a variable type CMyListControl in the View
Class .
You see the #include files are automatically added to the view
class.Right!!
When you open this view header file you dont see forward declarations
of class CMyListControl.
I guess my point is clear.
thanks
Bhargavi
The view does not need a forward declaration for a child. #include
"child" declares the child before the view uses it. But in the
situation you are having trouble with you are also trying to give the
child a pointer to the parent view, or to other controls. With such
cross referenced symbols they cannot all be #included first.

A forward declaration gives the compiler enough information about a
pointer to compile the class declaration that contains the pointer.
--
Scott McPhillips [VC++ MVP]
Bhargs
2006-05-26 16:21:05 UTC
Permalink
In one situation where I included header files and

For ex:
In class1.h
#include tab1.h

class Class
{
....
class *Tab1;
};

this worked for one case but for other class say CTab2 this did not
work out

#include tab2.h

class Class
{
....
class *Tab2;
};

but when i tried to use using the same waysay here I got an error that
missing storage specifier ,then when I made forward declaration of
class Tab2

Any guesses ....?

class tab2 and this time I did not include the header file of #include
"Tab1.h" and this works.
Ajay Kalra
2006-05-26 16:50:50 UTC
Permalink
What do you mean by this does not work out? This is basic C++ and has
nothing to do with MFC/tabs/views. Show you class definition in class
Tab2. What error do you get? Its very likely that you class is not
declared correctly.

---
Ajay
Bhargs
2006-05-26 17:39:00 UTC
Permalink
Pls observe the comments and this works even though I do not forward
declare it.
CUserDlg is a class derived from Dialog .
This works even though you do not forward declare it.

#include "MyListSeriesResltsCtrl.h"
#include "IconsListCtrl.h"
#include "UserDataDlg.h"

//class CUserDlg;

class CMyListSeriesCtrl : public CListCtrl
{
DECLARE_DYNAMIC(CMyListSeriesCtrl)
private:
BOOL m_bIsRowSelected;
int nSortedCol;
BOOL bSortAscending;

public:
CMyListSeriesCtrl();
virtual ~CMyListSeriesCtrl();
CMyListSeriesResltsCtrl *m_pmyListSeriesCtrl;
CIconsListCtrl *m_IconListCtrl;
CUserDataDlg *userDlg;

void SetListToFill(CMyListSeriesResltsCtrl *pListCtrl ){
m_pmyListSeriesCtrl = pListCtrl;

}
void SetTabToFill(CUserDataDlg *pCtrl ){
userDlg= pCtrl;
}

BOOL SortTextItems( int nCol, BOOL bAscending,
int low ,int high );
void SetApply();

protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLvnKeydownListResults2(NMHDR *pNMHDR, LRESULT
*pResult);
public:
afx_msg void OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult);
public:
afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
public:
afx_msg void OnLvnColumnclick(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnHeaderClicked(NMHDR* pNMHDR, LRESULT* pResult);
};
Ajay Kalra
2006-05-26 18:14:41 UTC
Permalink
this works even though I do not forward declare it.
Whats the problem then? You can do either way. Forward declaration is
superior as if you change the the class, it does not force a
recompilation in other files which are using it

---
Ajay

Loading...