Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how can i get this to work in c#

how can i get this to work in c#

Scheduled Pinned Locked Moved C#
csharpc++graphicsquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elfenliedtopfan5
    wrote on last edited by
    #1

    how would i go about converting this following code to c# my friend sent it to me but its in c++ and i have no idea what to do with it as i code in c# codenamespace Goat { struct IBaseWeapon { virtual ~IBaseWeapon() {} virtual string GetName(void) = 0; virtual bool AddToCsv(string& strOut) = 0; }; class Kap40 : public IBaseWeapon { public: Kap40() = default; virtual string GetName(void) { return "kap40"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, kap40_viewmodel\n"; strOut += "xmodel, kap40_worldmodel\n"; return true; } }; class Ak47 : public IBaseWeapon { public: Ak47() = default; virtual string GetName(void) { return "ak47"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, ak47_viewmodel\n"; strOut += "xmodel, ak47_worldmodel\n"; return true; } }; class WeaponsMng { public: WeaponsMng() = default; void AddWeapon(IBaseWeapon* pWeapon) { // check if already added etc.. // add it. weapons_.push_back(pWeapon); } void RemoveWeapon(const string& name) { for(auto w : weapons_) { const string& curName = w->GetName(); if(curName == name) { weapons_.remove(w); } } } string CreateCsc(void) { string res; for(auto w : weapons_) { w->AddToCsv(res); } // res now contains /* xmodel, kap40_viewmodel xmodel, kap40_worldmodel xmodel, ak47_viewmodel xmodel, ak47_worldmodel */ return res; } private: std::vector<IBaseWeapon*>

    D B L 3 Replies Last reply
    0
    • E elfenliedtopfan5

      how would i go about converting this following code to c# my friend sent it to me but its in c++ and i have no idea what to do with it as i code in c# codenamespace Goat { struct IBaseWeapon { virtual ~IBaseWeapon() {} virtual string GetName(void) = 0; virtual bool AddToCsv(string& strOut) = 0; }; class Kap40 : public IBaseWeapon { public: Kap40() = default; virtual string GetName(void) { return "kap40"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, kap40_viewmodel\n"; strOut += "xmodel, kap40_worldmodel\n"; return true; } }; class Ak47 : public IBaseWeapon { public: Ak47() = default; virtual string GetName(void) { return "ak47"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, ak47_viewmodel\n"; strOut += "xmodel, ak47_worldmodel\n"; return true; } }; class WeaponsMng { public: WeaponsMng() = default; void AddWeapon(IBaseWeapon* pWeapon) { // check if already added etc.. // add it. weapons_.push_back(pWeapon); } void RemoveWeapon(const string& name) { for(auto w : weapons_) { const string& curName = w->GetName(); if(curName == name) { weapons_.remove(w); } } } string CreateCsc(void) { string res; for(auto w : weapons_) { w->AddToCsv(res); } // res now contains /* xmodel, kap40_viewmodel xmodel, kap40_worldmodel xmodel, ak47_viewmodel xmodel, ak47_worldmodel */ return res; } private: std::vector<IBaseWeapon*>

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Understand exactly what this code is doing and rewrite in C#. You're friend sent it to you so he must have written it correct? He can explain it to you too. Nobody is going to convert it for you. It would seem there is a ton more going on in the rest of the code that this code interacts with, so a line-by-line conversion is probably not going to do anything for you.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • E elfenliedtopfan5

        how would i go about converting this following code to c# my friend sent it to me but its in c++ and i have no idea what to do with it as i code in c# codenamespace Goat { struct IBaseWeapon { virtual ~IBaseWeapon() {} virtual string GetName(void) = 0; virtual bool AddToCsv(string& strOut) = 0; }; class Kap40 : public IBaseWeapon { public: Kap40() = default; virtual string GetName(void) { return "kap40"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, kap40_viewmodel\n"; strOut += "xmodel, kap40_worldmodel\n"; return true; } }; class Ak47 : public IBaseWeapon { public: Ak47() = default; virtual string GetName(void) { return "ak47"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, ak47_viewmodel\n"; strOut += "xmodel, ak47_worldmodel\n"; return true; } }; class WeaponsMng { public: WeaponsMng() = default; void AddWeapon(IBaseWeapon* pWeapon) { // check if already added etc.. // add it. weapons_.push_back(pWeapon); } void RemoveWeapon(const string& name) { for(auto w : weapons_) { const string& curName = w->GetName(); if(curName == name) { weapons_.remove(w); } } } string CreateCsc(void) { string res; for(auto w : weapons_) { w->AddToCsv(res); } // res now contains /* xmodel, kap40_viewmodel xmodel, kap40_worldmodel xmodel, ak47_viewmodel xmodel, ak47_worldmodel */ return res; } private: std::vector<IBaseWeapon*>

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        You can try using the free C++ to C# converter here: [^], but I think the "translation" will only be useful to give you ideas about what the C++ code is doing, and how specific syntaxes map from C++ to C#. And, the output is likely to need considerable "massage." Until you understand the purpose and usage of the code, you are dancing in the dark. What I can say about the structure of the code, speaking as a "C/C++ non-native speaker", from a quick glance: ... of course you'll have a NameSpace .... a. you have an Interface 'IBaseWeapon ... the on-line converter would convert that to an abstract class. b. you will have (not static) classes, WeaponsMng, Ak47, Kap40 b.1. Ak47 and Kap40 will inherit from 'IBaseWeapon b.2. WeaponsMng keeps a List of IBaseWeapon c. you will have some static methods which should be put in a static class

        «In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”

        U 1 Reply Last reply
        0
        • E elfenliedtopfan5

          how would i go about converting this following code to c# my friend sent it to me but its in c++ and i have no idea what to do with it as i code in c# codenamespace Goat { struct IBaseWeapon { virtual ~IBaseWeapon() {} virtual string GetName(void) = 0; virtual bool AddToCsv(string& strOut) = 0; }; class Kap40 : public IBaseWeapon { public: Kap40() = default; virtual string GetName(void) { return "kap40"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, kap40_viewmodel\n"; strOut += "xmodel, kap40_worldmodel\n"; return true; } }; class Ak47 : public IBaseWeapon { public: Ak47() = default; virtual string GetName(void) { return "ak47"; } virtual bool AddToCsv(string& strOut) { strOut += "xmodel, ak47_viewmodel\n"; strOut += "xmodel, ak47_worldmodel\n"; return true; } }; class WeaponsMng { public: WeaponsMng() = default; void AddWeapon(IBaseWeapon* pWeapon) { // check if already added etc.. // add it. weapons_.push_back(pWeapon); } void RemoveWeapon(const string& name) { for(auto w : weapons_) { const string& curName = w->GetName(); if(curName == name) { weapons_.remove(w); } } } string CreateCsc(void) { string res; for(auto w : weapons_) { w->AddToCsv(res); } // res now contains /* xmodel, kap40_viewmodel xmodel, kap40_worldmodel xmodel, ak47_viewmodel xmodel, ak47_worldmodel */ return res; } private: std::vector<IBaseWeapon*>

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Did your friend tell you what the code is supposed to do? I can tell you it doesn't really "do" much of anything; the "intent" seems to be to provide functionality that will add / remove a weapon from your inventory; but by itself, the code cannot even do that unless it is properly integrated with the "main application" (whatever that may be).

          1 Reply Last reply
          0
          • B BillWoodruff

            You can try using the free C++ to C# converter here: [^], but I think the "translation" will only be useful to give you ideas about what the C++ code is doing, and how specific syntaxes map from C++ to C#. And, the output is likely to need considerable "massage." Until you understand the purpose and usage of the code, you are dancing in the dark. What I can say about the structure of the code, speaking as a "C/C++ non-native speaker", from a quick glance: ... of course you'll have a NameSpace .... a. you have an Interface 'IBaseWeapon ... the on-line converter would convert that to an abstract class. b. you will have (not static) classes, WeaponsMng, Ak47, Kap40 b.1. Ak47 and Kap40 will inherit from 'IBaseWeapon b.2. WeaponsMng keeps a List of IBaseWeapon c. you will have some static methods which should be put in a static class

            «In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”

            U Offline
            U Offline
            User 11678350
            wrote on last edited by
            #5

            I don't think it is productive to use a converter in this case because C# classes are managed classes while the given C++ class is a native one. For a Managed C++ (or formally, C++/CLI) class, we should write ref class instead of class - and objects are instantiated in this way:

            Object^ obj1 = gcnew Object(); // C++/CLI
            Object^ obj2 = ref new Object(); // C++/CX

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups