I’m writing a Windows Form Ap that manages a series of website. I created a website class then pre-loaded std::list<WebSite> from an INI file. Now I need to use that list in other places in the code so I tried to move it into the private member area and got the following error message:
error C4368: cannot define 'websites2' as a member of managed 'HowToInit::Form1': mixed types are not supported
Here is the code the class and also Form1.h. The commented out line 55 “private: std::list<WebSite> websitesX;” is what causes the error.
Lines 131 to end
private: System::Void Form1_Load(...) method is where I initialize the list currently.
#pragma once
#include <string>
class WebSite
{
public:
WebSite(void);
WebSite(std::string Name, std::string Path);
bool operator < (WebSite);
public:
std::string name;
std::string path;
};
#include "StdAfx.h"
#include "WebSite.h"
WebSite::WebSite(void)
{
}
WebSite::WebSite(std::string domainName, std::string localPath)
{
name = domainName;
path = localPath;
}
bool WebSite::operator < (WebSite param) {
unsigned int i=0;
while ( ( i < name.length() ) && ( i < param.name.length() ) )
{
if (tolower(name[i])<tolower(param.name[i])) return true;
else if (tolower(name[i])>tolower(param.name[i])) return false;
++i;
}
if (name.length()<param.name.length()) return true;
return false;
}
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include "WebSite.h"
void DoSomething(System::Windows::Forms::RichTextBox^ richTextBox);
namespace HowToInit {
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>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::RichTextBox^ richTextBox1;
// private: std::list<WebSite> websitesX;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->SuspendLayout();
//
// comboBox1
//
this->comboBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Location = System::Drawing::Point(25, 25);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(121, 28);
this->comboBox1->TabIndex = 0;
this->comboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(170, 28);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(51, 20);
this->label1->TabIndex = 1;
this->label1->Text = L"label1";
//
// richTextBox1
//
this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->richTextBox1->Location = System::Drawing::Point(25, 90);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(529, 56);
this->richTextBox1->TabIndex = 2;
this->richTextBox1->Text = L"";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(588, 270);
this->Controls->Add(this->richTextBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->comboBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
int idx = this->comboBox1->SelectedIndex;
System::String ^ txt = this->comboBox1->SelectedItem->ToString();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
using namespace std;
std::list<WebSite> websites;
WebSite * newsite;
string line;
std::string lastSite;
lastSite = "";
ifstream myfile ("HowToInit.ini");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
if (line.size() < 2)
continue;
size_t tabpoint = line.find_first_of('\t');
std::string name = line.substr(0,tabpoint).c_str();
std::string path = line.substr(tabpoint+1).c_str();
if (name.compare("Last:"))
{
newsite = new WebSite(name,path);
websites.push_back(*newsite);
}
else
lastSite = path;
}
myfile.close();
}
else
{
// create dummy file here
}
websites.sort();
std::list <WebSite>::iterator webSiteIter;
int i = 0;
int SelectedIndex = 0;
for ( webSiteIter = websites.begin(); webSiteIter != websites.end();webSiteIter++)
{
this->comboBox1->Items->Add(gcnew String(webSiteIter->name.c_str()));
std::string showName;
showName = webSiteIter->name;
if ( showName.compare(lastSite) == 0 )
{
SelectedIndex = i;
this->label1->Text = gcnew String(webSiteIter->path.c_str() );
}
i++;
}
this->comboBox1->Items->Add("New Website");
this->comboBox1->SelectedIndex = SelectedIndex;
}
};
}