首页 \ 问答 \ 将类继承为static(Inherit a class as static)

将类继承为static(Inherit a class as static)

我在C ++中有以下结构:

class A
{
protected:
  int a;
};

class B : public A
{
public:
  static void initThreads();  //Initialize threads (pthreads)
  /* Threads */
  static void* send(void*);
  static void* receive(void*);
}

这些“发送”和“接收”功能在“a”上运行。 但是无法在静态函数中编辑非静态成员。 因为发送和接收是线程,因此需要将它们定义为静态。 虽然有多个A类对象,但我只有一个B类对象。

那么,有没有办法以某种方式在“发送”和“接收”中使用“a”?


I have the following structure in C++:

class A
{
protected:
  int a;
};

class B : public A
{
public:
  static void initThreads();  //Initialize threads (pthreads)
  /* Threads */
  static void* send(void*);
  static void* receive(void*);
}

These functions "send" and "receive" operate on "a". But a non-static member cannot be edited in a static function. Because send and receive are threads, hence they need to be defined as static. I would have only 1 object of class B, though there are multiple objects of class A.

So, is there a way to use "a" within "send" and "receive" in some manner?


原文:https://stackoverflow.com/questions/6416019
更新时间:2023-08-17 20:08

最满意答案

NUnit WRT配置文件设计背后的思想是,测试程序集的配置文件不会总是与您的应用程序的配置文件相匹配。

因此,nunit将您的测试程序集AppDomain的配置文件设置为您的测试dll +“.config”的名称。 NUnit对此配置文件不做任何处理 - 它不会读取它 - 所以NUnit不可能以某种方式跟随第二个配置文件的链接。 只有.NET运行时和测试程序集本身知道或可以访问此配置。


I managed to figure out the issue on my own. In my case, I had two .config files; both in my windows service project, one called App.config and the other called Connections.config.

My connection strings were hidden away in Connections.config in order to make sure they were not included in source control but still accessible by the application.

The solution was to take the App.config file from the 'ServiceTemplate' project and rename it to 'ServiceTemplateUnitTesting.dll.config' and placing it in the 'ServiceTemplateUnitTesting' project's /bin/debug folder. Along with this, I also placed a copy of the Connections.config file in the /bin/debug folder of 'ServiceTemplateUnitTesting'. After this, the loaded NUnit test dll was able to read my original App.config file.

It may be a good idea to add a post build option to the solution to xcopy the config file from your starting application and renaming it to the test assembly and placing it within the test assembly's /bin/debug.

相关问答

更多
  • 您需要将配置文件添加到您的测试项目中,因为它不知道您的Web项目,并且没有看到NH配置文件。 You need to add config file into your tests project because it doesn't know about your web project and doesn't see NH config file.
  • 使用反射,你可以(在内存中)改变Configuration.ConnectionStrings [connectionName]的值,在你的情况下你可能会在SetUp或TestFixtureSetUp中做这些。 请参阅http://david.gardiner.net.au/2008/09/programmatically-setting.html 。 // Back up the existing connection string ConnectionStringSettings connStringS ...
  • 从MSDN文档的主题: Transform="Remove"是您要寻找的魔力。 还有一个Transform="RemoveAll" ,您可能会与特定的添加一起使用。 编辑 第二个想法你也可以将Locator属性与上面定义的Remove ,以限制实际要删 ...
  • 为了建立SQL连接,您需要先解密连接字符串,下面的代码将指导您正确的方向。 DataSet dsConnection = new DataSet(); dsConnection.ReadXml(System.Web.Hosting.HostingEnvironment.MapPath("~/ConnectionString.Config.xml")); String connection = dsConnection.Tables[0].Rows[0]["connectionstring"].ToStrin ...
  • NUnit WRT配置文件设计背后的思想是,测试程序集的配置文件不会总是与您的应用程序的配置文件相匹配。 因此,nunit将您的测试程序集AppDomain的配置文件设置为您的测试dll +“.config”的名称。 NUnit对此配置文件不做任何处理 - 它不会读取它 - 所以NUnit不可能以某种方式跟随第二个配置文件的链接。 只有.NET运行时和测试程序集本身知道或可以访问此配置。 I managed to figure out the issue on my own. In my case, I h ...
  • 我把一切都搞定了,我能想到的唯一原因就是我删除了我的ASP .NET 4.0临时文件。 此外,我必须添加我改变我的过程从使用集成测试来测试这个部分到使用单元测试。 我没有先进行单元测试,因为我们的构建服务器上没有数据库。 一旦我能够证明它在那里工作,我决定删除我的临时文件。 在那之后,一切都开始正常运作。 因此,我的应用程序中出现了某种缓存问题。 我使用了上面提到的相同的connectionString。 实际上,我使用元数据的域名“metadata = res://MyDomain/MyEntititie ...
  • 这听起来很巧合。 连接字符串是坏的,一切都应该失败,或者它很好,无论你是在web.config中硬编码还是使用Azure设置,它都应该完全相同。 将其置于Azure设置会导致它在运行时注入.NET配置系统。 那时,这两个案件基本上没有区别。 This does sound coincidental. Either the connection string is bad, and everything should fail, or it's good and it should work identica ...
  • 在运行时,只有一个配置文件。 所以只考虑活动项目的配置文件。 另外,您不能将类库项目作为活动/启动项目,即 假设您的解决方案中有4个项目,并且每个项目都有一个配置文件,那么当您运行该应用程序时,只会识别活动项目(您的启动项目)项目配置文件。 那你能做什么? 如果您只想隔离配置文件的各个部分,那么您可以在每个项目中都有配置文件,而这些配置文件又在主项目配置中引用,即 Web.config文件: ...
  • 对于样本,您有不同的类模型: namespace MvcMusicStore.Models { public class Artist { public int ArtistId { get; set; } public string Name { get; set; } } } namespace MvcMusicStore.Models { public class Album { public int ...
  • 您的连接字符串必须在执行程序集的App.config中设置,而不是在直接使用它的程序集中设置。 这意味着虽然您的服务实现( Service.cs )位于WCF库程序集中,但连接字符串必须位于主机项目的App.config中。 如果将App.config文件声明到WCF库中,则只会忽略它。 客户端不会访问数据库,它将使用访问数据库的服务。 因此,无需在客户端App.config中声明connectiong字符串。 Your connection string must be set in the App.co ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。