将类添加到应用程序窗体表单 [英] add a class to a Application windows forms
问题描述
大家好!
i只想添加一个cless ConnectedComponent.cpp
# include < vector >
#include < iostream >
#include ConnectedComponent.h
#include < string >
使用 命名空间 s TD;
ConnectedComponent :: ConnectedComponent():m_nodes_number( 0 )
{
m_edges [m_nodes_number] [m_nodes_number];
for ( int i = 0 ; i< 5; i ++)
m_nodes.push_back( titi);
}
ConnectedComponent :: ~ConnectedComponent()
{
}
和一个ConnectedComponent类。 h
#ifndef DEF_CONNECTEDCOMPONENT
#define DEF_CONNECTEDCOMPONENT
#include < string >
#include < vector > ;
class ConnectedComponent
{
public :
ConnectedComponent();
virtual ~ConnectedComponent();
public :
std :: vector< std :: string> m_nodes;
int ** m_edges;
int m_nodes_number;
};
#endif
但是当我将它们添加到具有GUI
#pragma once
#include ConnectedComponent.h
命名空间 AWF {
使用 命名空间系统;
使用 命名空间 System :: ComponentModel;
使用 命名空间 System :: Collections;
使用 命名空间 System :: Windows :: Forms;
使用 命名空间 System :: Data;
使用 命名空间 System :: Drawing;
/// < 摘要 >
/// 说明résuméedeForm1
/// < / summary >
public ref class Form1: public System :: Windows :: Forms :: Form
{
public :
Form1( void )
{
InitializeComponent();
//
// TODO:ajoutez ici le code du constructeur
//
}
受保护:
/// < 摘要 >
/// Nettoyage desressourcesutilisées。
/// < / summary >
~Form1()
{
if (components)
{
delete 组件;
}
}
private :System :: Windows :: Forms :: Button ^ button1;
受保护:
私人:
/// < 摘要 >
/// 变量nécessaireauconcepteur。
/// < / summary >
System :: ComponentModel :: Container ^ components ;
#pragma region Windows窗体设计器生成的代码
/// < 摘要 >
/// Méthoderequise pour la prize en charge du concepteur - ne modifiez pas
/// le contenu decetteméthodevevel'éditeur代码。
/// < / summary >
void InitializeComponent( void )
{
this - > ; button1 =( gcnew System :: Windows :: Forms :: Button());
此 - > SuspendLayout();
//
// button1
//
此 - > button1-> Location = System :: Drawing :: Point( 78 , 83 );
此 - > button1->名称= L button1的跨度>;
此 - > button1->尺寸=系统::图纸::尺寸( 75 , 23 );
此 - > button1-> TabIndex = 0 ;
此 - > button1-> Text = L button1的跨度>;
此 - > button1-> UseVisualStyleBackColor = true ;
此 - > button1->点击+ = gcnew System :: EventHandler(< span class =code-keyword> this ,& Form1 :: button1_Click);
//
// Form1
//
此 - > AutoScaleDimensions = System :: Drawing :: SizeF( 6 , 13 );
此 - > AutoScaleMode = System :: Windows :: Forms :: AutoScaleMode :: Font;
此 - > ClientSize = System :: Drawing :: Size( 284 , 262 跨度>);
此 - > Controls->添加(此 - > button1);
此 - >名称= L Form1\" 中跨度>;
此 - > Text = L Form1\" 中跨度>;
此 - > ResumeLayout( false );
}
#pragma endregion
private : System :: Void button1_Click(System :: Object ^ sender,System :: EventArgs ^ e){
ConnectedComponent reader;
}
};
}
i有这样的错误:
1> ------Début delagénération:Projet:AWF,配置:调试Win32 ------
1> AWF.cpp
1> ConnectedComponent.cpp
1> ConnectedComponent.cpp( 1 ):警告C4627:' #include< vector>':ignorélolesde la recherche d ' une utilization d' un en-têteprécompilé
1> Ajoutez la directiveà' StdAfx.h'ourégénérezl ' en-têteprécompilé
1> ConnectedComponent.cpp(2):警告C4627:' #include < iostream > ':ignorélorsde la recherche d'une utilization d'un en-têteprécompilé
1> Ajoutez la directiveà' StdAfx.h'ourégénérezl ' en-têteprécompilé
1> ConnectedComponent.cpp(3):警告C4627:' #include ConnectedComponent.h' :ignorélorsde la recherche d'une utilization d'un en-têteprécompilé
1> Ajoutez la directiveà' StdAfx.h'ourégénérezl ' en-têteprécompilé
1> ConnectedComponent.cpp(4):警告C4627:' #include < string > ':ignorélorsde la recherche d'une utilization d'un en-têteprécompilé
1> Ajoutez la directiveà' StdAfx.h'ourégénérezl ' en-têteprécompilé
1> ConnectedComponent.cpp(20):致命错误C1010:fin de fichier inattendue lors de la recherche d' un en-têteprécompilé。 N ' auriez-vouspasoubliéd' ajouter ' #includeStdAfx.h'àvotresource?
1> Générationdecode en cours ...
==========Génération: 0 一个réussi, 1 aéchoué, 0 misàjour, 0 aétéignoré=== =======
如果有人可以帮助我,谢谢:)
恩,对于他,
#include < string >
#include < vector >
< / vector>< / string>
已被包含两次,首先在头文件ConnectedComponent.h中,然后再在i中实现文件ConnectedComponent.cpp。
在下面,我有理由相信iostream在某处:
命名空间 AWF {
使用 命名空间系统;
使用 命名空间 System :: ComponentModel;
使用 命名空间 System :: Collections;
使用 命名空间 System :: Windows :: Forms;
使用 命名空间 System :: Data;
使用 命名空间 System :: Drawing;
但真正的问题是:
#include < vector < span class =code-keyword>>
#include < span class =code-keyword>< iostream >
#include ConnectedComponent.h
#include < string >
使用 命名空间标准;
// using namespace std;应该在#pragma之后,但在#includes之前
根据你的警告列出这些四个#include语句,它告诉您它们已经包含在您的StdAfx.h文件中。 。
Hi all !
i just want to add a cless ConnectedComponent.cpp
#include <vector>
#include <iostream>
#include "ConnectedComponent.h"
#include <string>
using namespace std;
ConnectedComponent::ConnectedComponent(): m_nodes_number(0)
{
m_edges [m_nodes_number][m_nodes_number];
for (int i=0; i<5; i++)
m_nodes.push_back("titi");
}
ConnectedComponent::~ConnectedComponent()
{
}
and a class ConnectedComponent.h
#ifndef DEF_CONNECTEDCOMPONENT
#define DEF_CONNECTEDCOMPONENT
#include <string>
#include <vector>
class ConnectedComponent
{
public:
ConnectedComponent();
virtual ~ConnectedComponent();
public:
std::vector<std::string> m_nodes;
int **m_edges;
int m_nodes_number;
};
#endif
but when i add them to anthor class which has the GUI
#pragma once
#include "ConnectedComponent.h"
namespace AWF {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Description résumée de Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: ajoutez ici le code du constructeur
//
}
protected:
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(78, 83);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
ConnectedComponent reader;
}
};
}
i have got this errors :
1>------ Début de la génération : Projet : AWF, Configuration : Debug Win32 ------
1> AWF.cpp
1> ConnectedComponent.cpp
1>ConnectedComponent.cpp(1): warning C4627: '#include <vector>' : ignoré lors de la recherche d'une utilisation d'un en-tête précompilé
1> Ajoutez la directive à 'StdAfx.h' ou régénérez l'en-tête précompilé
1>ConnectedComponent.cpp(2): warning C4627: '#include <iostream>' : ignoré lors de la recherche d'une utilisation d'un en-tête précompilé
1> Ajoutez la directive à 'StdAfx.h' ou régénérez l'en-tête précompilé
1>ConnectedComponent.cpp(3): warning C4627: '#include "ConnectedComponent.h"' : ignoré lors de la recherche d'une utilisation d'un en-tête précompilé
1> Ajoutez la directive à 'StdAfx.h' ou régénérez l'en-tête précompilé
1>ConnectedComponent.cpp(4): warning C4627: '#include <string>' : ignoré lors de la recherche d'une utilisation d'un en-tête précompilé
1> Ajoutez la directive à 'StdAfx.h' ou régénérez l'en-tête précompilé
1>ConnectedComponent.cpp(20): fatal error C1010: fin de fichier inattendue lors de la recherche d'un en-tête précompilé. N'auriez-vous pas oublié d'ajouter '#include "StdAfx.h"' à votre source ?
1> Génération de code en cours...
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========
if ay one can help me thanks :)
Well for une,
#include <string> #include <vector> </vector></string>
have been included twice, first in the header file, "ConnectedComponent.h", then again in the implementation file "ConnectedComponent.cpp".
And in the following, I'm reasonably sure that iostream is in there somewhere:
namespace AWF { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing;
But the real issue IS:
#include <vector> #include <iostream> #include "ConnectedComponent.h" #include <string> using namespace std; //The using namespace std; should come after #pragma's, but before #includes
AS YOUR WARNINGS listed these four #include statements, it is telling you that they have ALREADY BEEN INCLUDED IN YOUR StdAfx.h file . . .
这篇关于将类添加到应用程序窗体表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!