C# to C++ static class -


i porting code c# c++. not sure how create class static class in c#.

// in c# public static temperatureclass{   private static int offset = 50;   private static context context;    public static calculatetemperature(){   //use a;   //use context;   }    public static context con{     set{         context = value;       }   } }  int main() {  context con1;  temperatureclass.con = con1; //con1   temperatureclass.calculatetemperature(); } 

basically temperatureclass utility class perform calculation no instances created. have few questions:

  1. should c++ version of calculatetemperature remain static?
  2. how initialize int offset in c++ if keep static because used static calculatetempearture function?
  3. should keep con accessor static in c++ need set context?

or more generally, way of implementing utility class in c++?

  1. the c++ version class containing static members
  2. the offset variable being of integral type, can initialized same way in c# if declared static (but might want add const)
  3. if context static, accessor must static static member functions cannot access non-static member variables

note don't think design. point of view, there isn't sense in "whole static classes" in c++, , i'd rather use set free functions in isolated namespace. if choose "static class" approach anyway, i'd recommend declaring default constructor private make clear class has not point in being instantiated.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -