struct with classes

Hi all,

I would like to use a struct in c++ with classes

I use visual studio

it does not allow me to define it within the current class

my visual studio files

Form1.h this is where my button function is.

label writer.cpp this is where main is.

I would like to access the same struct and data from different classes is this possible.

I can define and declare a struct in label writer.cpp and access it from there but I would like to access the data from Form1.h how can I do this.

I have watched some video's but it is still not clear.

please help.

Kind regards,

Jorz
Can you give an example of what you are trying to do that isn't working?
Something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
struct Point {
  int x;
  int y;
  int z;
};

struct Vect3D {
  int x;
  int y;
  int x;
};

class Plane {
private:
  Vect3D v;
  Point p;
public:
  // Do stuff with these structs here  
};
Last edited on
I can do that Stewbond in my cpp file but the issue is I need to access them in .hpp file this is where my button stuff is done.

.cpp file
#include "stdafx.h"
#include "Form1.h"

using namespace Labelwriter;



// EbayData EBAYDATA1;




[STAThreadAttribute]
int main(array<System::String ^> ^args)
{


// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

and my Form1.h file

#pragma once
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
namespace Labelwriter {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;

/// <summary>
/// Summary for Form1
/// </summary>

//extern EbayData EBAYDATA1;

class EbayData {
// visibility will default to private unless you specify it
public:
//int dildo;
struct Struct {
char test;
//SalesRecordNumber[10];
//specify members here;
};
//Struct pussy;
};



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::DataGridView^ dataGridView1;
private: System::Windows::Forms::Button^ button1;
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->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
this->button1 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit();
this->SuspendLayout();
//
// dataGridView1
//
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView1->Location = System::Drawing::Point(249, 310);
this->dataGridView1->Name = L"dataGridView1";
this->dataGridView1->Size = System::Drawing::Size(240, 150);
this->dataGridView1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(267, 111);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
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(693, 410);
this->Controls->Add(this->button1);
this->Controls->Add(this->dataGridView1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit();
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {


FILE * pReadFile;
FILE * pWriteFile;

//This is where I would like to access the struct so I can save my data


}




Does anyone know how to do this?
Topic archived. No new replies allowed.