Visual studio 2013 -如何在已经包含#include的对象上添加一个对象?c++ / cli

visual studio 2013 - how to #include an object on another object that already has this #include? c++/cli

本文关键字:添加 对象 一个对象 cli c++ #include 包含 2013 studio Visual      更新时间:2023-10-16

我正在使用c++/cli,并且我有几个这样的问题。

Form1:有一个#include "UserControl1.h"

UserControl1:必须有#include "Formulario1.h"

原因:

UserControl1上显示的Form1。有一次Usercontrol1必须在Form1中运行一个方法,如果不使用#include "Formulario1.h"

就不能访问Form1类型。

I try this way access Form1

(static_cast <FormDICOM ^> (this-> Parent)) -> ControleUC (1, false);
(static_cast <FormDICOM ^> (this-> Parent)) -> ControleUC (2, true);

,但我得到错误在UserControl1, FormDICOM类型不存在。代放置#include "FormDICOM.h",但FormDICOM已经有#include "UserControl1.h"并出现错误!

FormDICOM和UserControl1在同一个命名空间!

Form1:有一个#include " usercontrol .h"

UserControl1:必须有一个#include "Formulario1.h"

在每个(和每个)头文件中放置多个'include guard'。

inside usercontrol .h头文件

#ifndef USER_CONTROL1_H 
#define USER_CONTROL1_H
#include "Formulario1.h"
 ..... <-- all the rest of the UserControl1.h header file contents
#endif // USER_CONTROL1_H
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
notice all caps and underscores like any #define should be, with 
the  USER_CONTROL1_H strongly related to the name of the header file
Do NOT use leading underscores in the defined name as that
can be mis-interpreted by the compiler 
as the compiler prepends 1 or more underscores
on most all names it keeps in its' symbol table

在formularia .h头文件

#ifndef FORMULARIO1_H
#define FORMULARIO1_H
#include "UserControl1.h"
---- <-- all the rest of the Formulario1.h header file contents
#endif // FORMULARIO1_H