|
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class.
Thanks in advance
|
|
|
|
|
C++ requires freestanding empty objects to have non-zero size. Most compilers automatically insert a char into "empty" objects to satisfy this. However, if your empty class is a base class then it won't add any size to the derived class object.
See: http://msdn2.microsoft.com/en-us/library/f42z47h2(VS.80).aspx[^]
You cannot create an object directly from an abstract class since it contains virtual method(s) without implementation(s).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Monday, December 10, 2007 3:25:41 PM
|
|
|
|
|
Giving them the smallest possible non-zero size makes sure different objects
result in different pointer/reference values, which is what you hope to get isn't it?
|
|
|
|
|
philiptabraham wrote: i also want to know why we cant create an object for an abstract class
If you could, the class wouldn't be abstract.
It doesn't make sense to create an object of a class that
has virtual functions that are NULL.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Monday, December 10, 2007 3:15:35 PM
|
|
|
|
|
Mark Salsbery wrote: It doesn't make sense to create an object of a class that
doesn't have a complete implementation.
You can make a class non-copyable by declaring a private copy constructor (and assignment operator) without an implementation!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
right. badly worded - I changed it a bit. It took a long time
for CP to let me edit it (or reply to you ).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello!
Being new to C++/CLI I'm trying to create a MVC design pattern as a start. Sadly I'm stuck with event management. Here is my code so far:
Controller.h
<br />
#pragma once <br />
#include "Model.h" <br />
#include "View.h" <br />
<br />
public ref class Controller <br />
{ <br />
private: Model^ mainModel; <br />
private: View^ mainView; <br />
<br />
public: Controller(void) { <br />
mainModel = gcnew Model(); <br />
mainView = gcnew View(this); <br />
Application::Run(mainView); <br />
} <br />
public: System::Void Btn_Open_Click(System::Object^ sender, System::EventArgs^ e) {<br />
}<br />
};<br />
View.h
<br />
#pragma once <br />
ref class Controller; <br />
<br />
public ref class View : public System::Windows::Forms::Form <br />
{ <br />
private: Controller^ mainController; <br />
public: View(Controller^ con) { <br />
mainController = con; <br />
InitializeComponent(); <br />
} <br />
InitializeComponent() { <br />
... <br />
this->Btn_Open->Click += gcnew System::EventHandler(this, &mainController::Btn_Open_Click);<br />
...<br />
} <br />
With MCV the controller is responsible for event managment. That's why I choose to create the View with a reference to the controller.
But now I'm stuck with the EventHandler. The code above compiles fine when the last line is commented out. Of course, then there is no event handler.
So what is the correct way to do this? I just want the EventHandler in the View class to call a method in another class. How to do that?
Thanks for your help and suggestions!
|
|
|
|
|
Windows Forms is based partially on MVC design pattern but it is not a pure implementation of it. Thus, you are doomed in implementing MVC with it as your base.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
atzplzw wrote: With MCV the controller is responsible for event managment.
Other patterns can be introduced into the MVC design like a Command Pattern. Strictly speaking your controller class does NOT have to be directly hooked to the event of the user interface control.
Also have you seen this[^]?
|
|
|
|
|
|
Hi,
there is an "as" operator that returns either a new reference of the indicated type,
or a null value. Example:
public: Int32 __gc* Compare(Object __gc* object1, Object __gc* object2)
{
ProcessModule __gc* module1 = (object1 as ProcessModule);
ProcessModule __gc* module2 = (object2 as ProcessModule);
return String::Compare(module1->FileName, module2->FileName, true);
}
BTW: the above is Reflector output of an assembly based on C# code.
|
|
|
|
|
C++/CLI does not have an "as" operator like C#. You have to use dynamic_cast or static_cast.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi George,
indeed, I have no reference to the "as" keyword in C++, except for the fact
that Reflector uses it.
MSDN itself shows how to use casts to simulate C#'s as , as you indicated.
|
|
|
|
|
You can use dynamic_cast:
if (dynamic_cast<TextBox^>(control) != nullptr)
{
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
We're interested in subclassing a window in order to handle window messages (specifically mouse click and movement).
Our current approach is to derive a listener class from NativeWindow, assign it the handle to the window in question, and then set up a message handler to handle the incoming messages.
The behavior we’re seeing is that only a very few windows messages come down to our listener class. (Mainly WM_NCHITTTEST).
Any ideas?
|
|
|
|
|
Hi fellas
I have a program that is currently wrote in Managed C++ within the MS Visual Studio 2005 environment i was wondering if there is anyway i can migrate it to C#.NET without having to re-code it?
Any help would be majorly appricated fellas
thanks
|
|
|
|
|
Our C++ to C# Converter utility will get you part of the way there (there will be some adjustments you'll have to make, but the conversion quality is pretty good for Managed C++ or C++/CLI).
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
C++ to C++/CLI Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
i have been looking at that one mate, i have a good part of it converted by doing it myself and using that software above, only problem is i do not knonw the difference between .CPP files and .h files. there is some of them in my project with the same name for example game.h and game.cpp how would i encorporate them into one c# class??
thanks and sorry for being niave, not a big user of c++
thanks again
|
|
|
|
|
'C++ to C# Converter' takes care of that. During the conversion, it automatically merges the header file with the same name into the conversion input (in C++, '#include' just inputs the file at the location of the #include before compilation).
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
C++ to C++/CLI Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
what happens if there is two header files, i can only select one at a time
thanks
|
|
|
|
|
C++ to C# Converter will process all header files.
You can also choose to embed all header files in the converted output, but I doubt that you'd want to do this.
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
C++ to Ruby Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|
|
Hi,
if your code is managed .NET code and builds to a working EXE or DLL file,
you should be able to use Reflector and convert it to source code in any of
the .NET languages; if successfull this would result in compilable code but will
lack any kind of comments your original may hold.
|
|
|
|
|
fellas i have been trying to covert it and cannot, i dont know what i am doinf wrong, i have tried refecltor and C++ to C#
if i would upload my orginal C++ program and the new C# with all the interfaces built without any code would somebody be kind enough to convert it as you guys know what you's are talking about and would have it done alot quicker
id be ever so appriceative
thanks fellas
PS could you let me know either way?
thanks
|
|
|
|
|
Sorry I do not intend on doing your work, and I don't expect any one else will either;
this forum is for helping people with a specific question or problem.
|
|
|
|
|
hello,
I would have a question about the C++ defined types to be available in .NET applications.
We have some implementation in C++, and we have been defining some classes that use templates and do some smart things. Now we have a need to be able to use those classes in C# for example, probably using an intermediate C++ CLI class-library.
The problem is how to make available those classes without to write for each class in native C++ an analog class in the C++ CLI module ? The CLI module will only include the native C++ code.
ex of what I'm looking to achieve:
C++, file "myclass.h"
class MyClass{};
class MyPipe
{
......void SendObject( MyClass& myClass );
}
C++ CLI
#include "myclass.h"
namespace BridgeClassLibrary {
....class PipeWrpper {
..........void SendObject( MyClass& myClass ){
...............MyPipe pyPipe( "super-pipe" );
...............pipe.SendObject( myClass );
..........}
....}
}
C#
using BridgeClassLibrary ;
namespace Logics.Test {
.....class PipeTester {
........static void Main( string[] args ) {
............MyClass myClass;
............PipeWrpper pipeWrpper;
............pipeWrpper.SendObject( myClass );
........}
.....}
}
modified on Friday, December 07, 2007 11:31:20 AM
|
|
|
|