partial class how-to?

hi, i have been looking at the microsoft help files and how-to's with no luck on finding how to create a partial class. I need to create a partial class for a datatable i am using.

the first information i found just didnt work at this location in the help file...
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_raddata/html/dfbc21eb-7ea2-4942-addd-49677f5493be.htm


the link on that page to the partial class definitions also didnt work when it tried to connect to the internet :s i found it anyway...
http://msdn2.microsoft.com/en-US/library/wa80x488.aspx

that is c# code obviously which i commonly find, but is usually easy to convert. However, in this case I just couldnt get it to compile. I created a new .cpp file and added an empty class to it, starting small, but no luck.

can anybody give me some sample code or a link to how to do this in Visual C++ 2005 Express Edition

thanks for any help



Answer this question

partial class how-to?

  • Randall Sutton

    The concept of partial classes is not supported in C++. Why exactly do you want to use that

    evilc wrote:
    hi, i have been looking at the microsoft help files and how-to's with no luck on finding how to create a partial class. I need to create a partial class for a datatable i am using.

    the first information i found just didnt work at this location in the help file...
    ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_raddata/html/dfbc21eb-7ea2-4942-addd-49677f5493be.htm


    the link on that page to the partial class definitions also didnt work when it tried to connect to the internet :s i found it anyway...
    http://msdn2.microsoft.com/en-US/library/wa80x488.aspx

    that is c# code obviously which i commonly find, but is usually easy to convert. However, in this case I just couldnt get it to compile. I created a new .cpp file and added an empty class to it, starting small, but no luck.

    can anybody give me some sample code or a link to how to do this in Visual C++ 2005 Express Edition

    thanks for any help



  • Netscorpion

    evilc wrote:
    You are exactly right, i do need to add an event handler. The problem is I cant add the event handler to the auto generated code made by the dataset designer, because it just deletes it every time the code is compiled.

    Without seeing your code, I can only make a guess - since I haven't used a data set designer previously.

    But in the source file, there is a block where the compile generates code, and there is probably an area outside it that the compiler leaves alone. If you put your code outside that region (where the compiler puts auto generated code), your code will not be erased.



  • LenKelly

    In a sense, partial classes have always been supported in C++.  You declare your class methods in one header file, and you spread our your implementation across files.  The ability to spread out the implementation of a C# class across files is a new feature in C# 2.0 called "Partial Classes." Is this what you were thinking of

    If you want to extend an existing C++ class by adding methods without changing the original declaration (h file), then no you cannot do that.  Either add the code to the original class, or inherit from it and do the specialized stuff in the derived class.

    Brian


  • macadam

    You are exactly right, i do need to add an event handler. The problem is I cant add the event handler to the auto generated code made by the dataset designer, because it just deletes it every time the code is compiled.


  • BydandConsulting

    ok, im still working on this problem, i had another thread which has now merged into the same question, so for any comments, please head over to...
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=310298&SiteID=1


  • BhavinG

    evilc wrote:
    guess i better explain what i want to do then...

    i have been using the dataset designer in visual c++ and i want to catch an event on an sql update so I can then execute an identity query to get the id of the new entry.

    this path i have chosen seems like the most appropriate way until the "c++ does not have partial classes" statement was made.

    so i guess the question is, how can i catch this event so i can execute my code in c++

    There must be a way and im guessing its by adding the code to a dataset.cpp file maybe


    Any help/links plus code examples would be welcome.

    Your situation does not seem to demand the use of partial classes at all. You merely need to add an event handler. I presume you are using C++/CLI - look up http://msdn2.microsoft.com/en-US/library/4b612y2s(VS.80).aspx



  • Ricardo Casquete

    Brian Kramer wrote:

    In a sense, partial classes have always been supported in C++. You declare your class methods in one header file, and you spread our your implementation across files. The ability to spread out the implementation of a C# class across files is a new feature in C# 2.0 called "Partial Classes." Is this what you were thinking of

    If you want to extend an existing C++ class by adding methods without changing the original declaration (h file), then no you cannot do that. Either add the code to the original class, or inherit from it and do the specialized stuff in the derived class.

    Brian

    C# partial classes allow you to not only split the implementation into multiple files, but also the definition (since in C# they are the same). That is not possible in C++ though. So you really cannot simulate exact partial class behavior in C++



  • Mei Liang - MSFT

    guess i better explain what i want to do then...

    i have been using the dataset designer in visual c++ and i want to catch an event on an sql update so I can then execute an identity query to get the id of the new entry.

    this path i have chosen seems like the most appropriate way until the "c++ does not have partial classes" statement was made.

    so i guess the question is, how can i catch this event so i can execute my code in c++

    There must be a way and im guessing its by adding the code to a dataset.cpp file maybe


    Any help/links plus code examples would be welcome.


  • dispehrse

    that is the case for form generated code, but not for the dataset generated code, the whole file is generated, not just parts of it. I am forced to move on to other work at the moment, I will look further into it down the track.


  • partial class how-to?