I’ve one header file which is just methods, a second C++ file where those methods are implemented, and a third main file where I want to call a method from second C++ file.
I have shown on which lines the errors occur with comments.
Root.h file (just methods):
class Root
{
//File
public: void NewFile(void);
public: void OpenFile(void);
public: void SaveFile(void);
public: void SaveAsFile(void);
public: void Print(void);
public: void Exit(void);
//Edit
public: void Undo(void);
public: void Redo(void);
public: void Cut(void);
public: void Copy(void);
public: void Paste(void);
public: void SelectAll(void);
//Tools
public: void Options(void);
//Help
public: void About(void);
};
Root.cpp
#include "stdafx.h"
#include "Root.h"
using namespace System::Windows::Forms;
using namespace System::IO;
class Nroot : public Root
{
void OpenFile()
{
OpenFileDialog^ opf = gcnew OpenFileDialog();
opf->InitialDirectory = "C://";
opf->Filter = "Text Files|*.txt";
if(opf->ShowDialog() == DialogResult::OK) //here is first error C3063: operator '==': all operands must have the same enumeration type
{
StreamReader^ sr = gcnew StreamReader(opf->FileName);
MessageBox::Show(sr->ReadToEnd());
}
}
};
Main File (just event)
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Nroot nr;
nr.OpenFile; //here is second error C3867: 'WindowsFormsApplication2::Nroot::OpenFile': function call missing argument list; use '&WindowsFormsApplication2::Nroot::OpenFile' to create a pointer to member c:\users\srdjan\documents\visual studio 2012\projects\windowsformsapplication2\windowsformsapplication2\Form1.h 325
}
Looks like
DialogResult::OKenumeration value defined differently more then in one place, so you have to use full path to the value:::System::Windows::Forms::DialogResult::OK. At least MSDn example does so:You’ve forgotten parenthesis:
To access
Nroot::OpenFile()outside of the class, you should make itpublic. Inc++, private access modifier is applied to members by default: