Click here to Skip to main content
16,014,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFileFind Pin
Christian Graus3-Apr-02 9:44
protectorChristian Graus3-Apr-02 9:44 
Generali know this has to be a simple question. Pin
jafrazee3-Apr-02 6:21
jafrazee3-Apr-02 6:21 
GeneralRe: i know this has to be a simple question. Pin
Joaquín M López Muñoz3-Apr-02 6:21
Joaquín M López Muñoz3-Apr-02 6:21 
GeneralRe: i know this has to be a simple question. Pin
jafrazee3-Apr-02 6:34
jafrazee3-Apr-02 6:34 
GeneralRe: i know this has to be a simple question. Pin
Joaquín M López Muñoz3-Apr-02 7:24
Joaquín M López Muñoz3-Apr-02 7:24 
GeneralRe: i know this has to be a simple question. Pin
jafrazee3-Apr-02 7:44
jafrazee3-Apr-02 7:44 
GeneralRe: i know this has to be a simple question. Pin
Joaquín M López Muñoz3-Apr-02 7:43
Joaquín M López Muñoz3-Apr-02 7:43 
GeneralRe: i know this has to be a simple question. Pin
jafrazee3-Apr-02 9:40
jafrazee3-Apr-02 9:40 
all i have on the top of my file is
// creport.cpp : implementation file
//

#include "stdafx.h"
#include "cmain.h"
#include "creport.h"
//////////////////////i have also tried to creport.h before cmain.h
i did find the following article on msdn. i have not made any since of it yet though.

HOWTO: Declare Classes That Refer to Each Other

Q136005


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft C/C++ Compiler (CL.EXE)
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51, 1.52
Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 2.2, 4.0, 4.1, 5.0, 6.0

--------------------------------------------------------------------------------


SUMMARY
In C++, you may need to have two classes that contain data members that refer to the other class as in this example:


class B
{
A * x;
};

class A
{
B * x;
};
This article shows by example how to declare two classes that contain pointers to the other class. The two classes (A and B) are derived from other classes (C and D) to better demonstrate this issue.

If the two classes are not declared correctly, errors such as the following can occur:
test1.h(8) : error C2501: 'B' : missing decl-specifiers
test1.h(8) : error C2143: syntax error : missing ';' before '*'
test1.h(8) : error C2501: 'x' : missing decl-specifiers



MORE INFORMATION

Sample Code

/* Compile options needed: none
*/

//================================
// test1.h
//================================

#ifndef _a_
#define _a_

class B;

class A : public D
{
B * x;
};

#endif

//================================
// test2.h
//================================

#ifndef _b_
#define _b_

class A;

class B : public C
{
A * y;
};

#endif

//=================================
// test.cpp
//=================================

class C
{
int q;
};

class D
{
int p;
};

#include "test1.h"
#include "test2.h"

void main(void)
{
}

Additional query words: 8.00 8.00c 9.00 9.10



GeneralIMAP class Pin
Steve Schaneville3-Apr-02 5:54
professionalSteve Schaneville3-Apr-02 5:54 
GeneralRe: IMAP class Pin
Jon Hulatt3-Apr-02 21:20
Jon Hulatt3-Apr-02 21:20 
GeneralRun application in start up. Pin
Mazdak3-Apr-02 5:29
Mazdak3-Apr-02 5:29 
GeneralRe: Run application in start up. Pin
Jon Hulatt3-Apr-02 5:42
Jon Hulatt3-Apr-02 5:42 
GeneralRe: Run application in start up. Pin
Mazdak3-Apr-02 5:59
Mazdak3-Apr-02 5:59 
QuestionHow to change the listbox background? Pin
Hans Ruck3-Apr-02 4:55
Hans Ruck3-Apr-02 4:55 
AnswerRe: How to change the listbox background? Pin
Ravi Bhavnani3-Apr-02 5:22
professionalRavi Bhavnani3-Apr-02 5:22 
GeneralRe: How to change the listbox background? Pin
Hans Ruck3-Apr-02 5:37
Hans Ruck3-Apr-02 5:37 
GeneralRe: How to change the listbox background? Pin
Ravi Bhavnani3-Apr-02 5:43
professionalRavi Bhavnani3-Apr-02 5:43 
Generalstructures Pin
RK_20003-Apr-02 5:00
RK_20003-Apr-02 5:00 
GeneralRe: structures Pin
Paul M Watt3-Apr-02 6:08
mentorPaul M Watt3-Apr-02 6:08 
GeneralRe: structures Pin
3-Apr-02 6:11
suss3-Apr-02 6:11 
GeneralA DAO Problem ! Pin
3-Apr-02 4:48
suss3-Apr-02 4:48 
Generaldistorted bitmaps and meta's using diff resolutions Pin
IGeorgeI3-Apr-02 4:25
IGeorgeI3-Apr-02 4:25 
Generalreading from file Pin
Rajveer3-Apr-02 3:53
Rajveer3-Apr-02 3:53 
GeneralRe: reading from file Pin
3-Apr-02 4:02
suss3-Apr-02 4:02 
GeneralRe: reading from file Pin
alex.barylski3-Apr-02 4:31
alex.barylski3-Apr-02 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.