Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all !

i just want to add a cless ConnectedComponent.cpp
C++
#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
C++
#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
C++
#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 :
C++
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 :)
Posted
Comments
[no name] 1-Aug-13 21:15pm    
Well....have you tried adding StdAfx.h?
Sergey Alexandrovich Kryukov 1-Aug-13 22:39pm    
Yes, or work without precompiled headers...
—SA
Sergey Alexandrovich Kryukov 1-Aug-13 22:35pm    
Tag it "C++/CLI", not "C++", to avoid confusions.
—SA
Philippe Mori 2-Aug-13 23:43pm    
By the way, it is always a good idea to include matching header immediatly after precompiled header. Thus the first file to include should be precompiled header (except if disabled in project property) and immediatly after, you should include the header file that correspond to the current file and finally any other includes.

The reason to do that is to reduce the risk that an header file would compile only if some file is include before it. An header file should include any necessay file to compile by itself from the matching source file when included first.

By the way, as other has mentionned, the error message explicitly say that you forgot to include the precompiled header file. Add missing include (or if you don't want to uses precompiled headers then disabled them). Also, if you are using Visual Studio, it is fairly easy to get information about each error. Here since the message exactly tell you what to do, it should not be hard, to do what the message suggest.
The_Inventor 4-Aug-13 9:09am    
When I viewed the list of the usual #include 's , and found that I want to use some class' that I had developed, I #include d them in the StdAfx.h file, so that they got precompiled right along, and then I could declare a variable of said class in any other class that also had StdAfx.h included.

1 solution

Well for une,

C++
#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:

C++
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:

C++
#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 . . .
 
Share this answer
 
v3
Comments
Manel1989 4-Aug-13 21:28pm    
thank you very much for your help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900