I have a rather decent sized project and I am trying to split it up in multiple files. I am using MSVC++ 2010 as a Windows Form's application. I am trying to be able to access the form controls from the namespace and class from a user defined class in a separate file. The main autogenerated class is defined as so:
main.cpp:
namespace MyMainForm {
...
...
...
public ref class Form1: public System::Windows::Forms::Form
{
...
...
};
}
Than I have a class I created that I want to be able to access the GUI components that are in the Form1 class although they are "private" So I tried inherting as MyMainForm::Form1 but does not seem to work.
mynewclass.cpp:
class MyNewClass {
...
...
};
Any thoughts? Thanks for your help!
Edit:
When inherting like so:
class MyNewClass : MyMainForm::Form1 {
I get an error like this:
error C2654: 'MyMainForm' : is not a class or namespace name
error C2504: 'Form1' : base class undefined
The name of MyMainForm IS a namespace though defined in the main.cpp
Related
my topic description might be quite strange but I am struggeling with some problem I do not know how to describe better.
I have 2 classes in a Qt project, one named "Admin", the other one is "Klient" - for our English speakers: "Client". Now my code was from a group of students. They created the class "Klient" where they did an instance in "Admin". Code below:
admin.h
#pragma once
#include "Klient.h"
[...]
namespace Ui {
class Admin;
}
class Admin : public QWidget
{
Q_OBJECT
private:
[...]
public:
Klient klient;
Klient klientb;
};
Working with the object "klient" works perfectly. Now when I add another instance "klientb" (no misspelling!) of "Klient"...
Klient klientb
...the program suddenly crashes... And I do not know why.
Any search on the web didn't give me any point where to find an error.
Class "Klient":
klient.h
#pragma once
#include <QDate>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
[...]
class Klient
{
public:
Klient(void);
Klient(int fileid);
~Klient(void);
[...]
};
klient.cpp
#include "Klient.h"
Klient::Klient(void) : style_coded(5) {}
Klient::Klient(int fileid)
{
this->fileid=fileid;
}
Klient::~Klient(void) {}
Maybe anyone of you has a simple idea where to start? For me it seems very strange. Creating another object of the same class when I have the first one besides that working...
I also tried to create a new class with a different name AND: didn't work either. But when I say "Client client" in the constructor of class Admin, the program doesn't give me an error. Maybe I just don't get the simple fail...
My problem is as follows:
I got a Microsoft Visual C++ 2008 project and the order to organize all classes in it in nested namespaces. Now I get System::Resources::MissingManifestResourceException on runtime, because the custom System::Windows::Forms has a assembly ressource and with the new namespace, the old Resx-file does not fit anymore. My problem is now, that I have no idea how to reconnect it to the Form-class.
The old code of the Form was like:
namespace OldNamespace{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
The new code looks like:
namespace NewNamespace{
namespace GUI{
namespace MainWindow{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
}
}
I tried to adjust the filename of the created resource-file from the resx-file from
$(IntDir)\$(RootNamespace).$(InputName).resources
to
$(IntDir)\NewNamespace.GUI.MainWindow.MainForm.resources
But I am still getting System::Resources::MissingManifestResourceException on runtime.
What is my mistake?
I am writing unit test case for my internal method. I have made necessary changes in AssemblyInfo.cs of my mail class project
[assembly: InternalsVisibleTo("myunitest_assemblyname")]
now i can access my internal method in unit test case method.
but when i compile the code it is giving an error as below
Error 1 'main class project name' does not contain a definition for 'Process' and no extension method 'Process' accepting a first argument of type 'main class project name' could be found (are you missing a using directive or an assembly reference?)
my main class has strong name.
it would be great if some one point where i am missing.
main class structure
namespace Renewals
{
public class StateProcessor
{
internal virtual void PutEmailInQueue(DataTable dataTable)
{
}
}
}
//test class structure
namespace Renewals.Tests.Unit
{
[TestClass]
public class StateProcessorTest
{
[TestMethod]
public void PutEmailInQueueTest()
{
DateTime processingDate = Convert.ToDateTime("27-feb-2013"); ;
StateProcessor stateProcess = new StateProcessor(processingDate);
stateProcess.PutEmailInQueue(new DataTable());
}
}
}
PutEmailInQueue - this method giving me problem.
you wrote that your class use strong name.
I think you have to modify your InternalsVisibleTo() statement with the public key.
e.g.: [assembly: InternalsVisibleTo("friend_signed_B, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e3aedce99b7e10823920206f8e46cd5558b4ec7345bd1a5b201ffe71660625dcb8f9a08687d881c8f65a0dcf042f81475d2e88f3e3e273c8311ee40f952db306c02fbfc5d8bc6ee1e924e6ec8fe8c01932e0648a0d3e5695134af3bb7fab370d3012d083fa6b83179dd3d031053f72fc1f7da8459140b0af5afc4d2804deccb6")]
for more informations see: http://msdn.microsoft.com/en-us/library/bb385180.aspx
I'm working on a project in c++ and I stuck with no idea what is wrong. I've writen 4 classes and everything looked fine during work (under visual studio 2010). VS 'saw' all the definition, i could use auto-fill and sudgestions, but when I tried to compile the project it sudennly went blind. It's like I didnt include headers or something (which I did). The strange thing is there is no problem with working with those classes on VS (i can ctrl+space for hint, list of attributes and methods and all that stuff) but when i try to compile it says "ClassName" is not a type.
Quick sample of problem below:
ProButton.cpp:
#include "ProButton.h"
using namespace pGUI;
ProButton::ProButton( ... )
: ProControl( ... )
{
...
}
ProButton.h:
#ifndef __PRO_BUTTON__
#define __PRO_BUTTON__
#include <string>
#include "ProControl.h"
namespace pGUI
{
class ProButton :
public pGUI::ProControl
{
public:
//attributes
...
public:
//methods
...
};
}
#endif
but compiler says:
Error 291 error C2653: 'ProButton' : is not a class or namespace name
for this line in ProButton.cpp: ProButton::ProButton( ... )
It also says:
Error 23 error C2039: 'ProControl' : is not a member of 'pGUI'
Error 24 error C2504: 'ProControl' : base class undefined
and all similar errors for whole project. I have no idea what is wrong. Looks like my VS broke :D
Of course those (...) means there is code there, just not that important for now. I can upload all solution somewhere fi it will help.
edit//
About namespaces, all header files (classes declaration) are defined in namespace with:
namespace pGUI{
class ProClass
{
};
}
all definitions for these classes (in ProClass.cpp) are using:
using namespace pGUI;
at the beginning.
I think the problem is with order of including files.
Im not sure how this is supposed to be done. So far i have 4 classes that:
class ProGUI:
has a pointer to ProContainer
includes: ProContainer and ProControl
class ProContainer:
has pointers to: ProGUI and ProControl
class ProControl:
has a pointer to ProContainer
includes ProButton
is a base class for ProButton
class ProButton:
is a sub-class of ProControl
Those classes also uses irrlicht library and I'm not sure where to include it.
I had it included in my main file just before #include "ProGUI.h". This is also the only include in main. ProGUI.h .
//EDIT 2 -> solved
It was a problem with includes. I needed to rethink my inclusion order and add some forward declarations. Anyway that all seemed strange and took me a lot of time to figure i out. Thx for help. :)
It seems that you are using following statement:
using namespace pGUI;
Just before the class declaration:
class ProControl
{
};
Instead of using following approach:
namespace pGUI
{
class ProControl
{
};
}
The using namespace, as it says uses a namespace. You need to explicitly put something a namespace using namespace keyword followed by braces!
using namespace pGUI informs the compiler that it should look in the pGUI namespace to resolve existing names.
To declare or implement something in a namespace you need to be more specific. with either:
namespace pGUI
{
ProButton::ProButton( ... ) : ProControl( ... )
{
...
}
}
or:
pGUI::ProButton::ProButton( ... ) : ProControl( ... )
{
....
}
Personally, I consider any use of using namespace to be a lazy programmer hack that completely defeats the point of namespaces. But I digress. :)
I am making a Counter Strike mod and during compiling I am getting some errors:
Panel.cpp(715): error C2248: 'CInput::CVerifiedUserCmd' : cannot access private class declared in class 'CInput'
1> \SDK\\game\\client\\input.h(238) : see declaration of 'CInput::CVerifiedUserCmd'
1> \SDK\\game\\client\\input.h(39) : see declaration of 'CInput'
Line 715:
CInput::CVerifiedUserCmd* ver = NULL;
Declaration:
class CVerifiedUserCmd
{
public:
CUserCmd m_cmd;
CRC32_t m_crc;
};
How do I fix this?
You're probably trying to use a private inner class:
class A
{
class B
{
};
};
Simply make the class public if you wish to use it outside:
class A
{
public:
class B
{
};
};
EDIT:
If the class is private and it's part of a 3rd party lib, you're probably doing it wrong. Look for a different solution to your problem, it was made private for a reason.
Assuming that was your code put class
CVerifiedUserCmd
to public section of the outer class. Otherwise you cannot use CVerifiedUserCmd since it is private inner class.
You probably can't (unless you want to edit the engine itself) - look for a better solution to your problem. Basically, don't try to manually instantiate CInput::CVerifiedUserCmd.