我正在使用Eclipse CDT(Helios发行版,CDT 7.0)和C++ Makefile项目.由于我是Eclipse新手,我想知道如何正确管理包含目录.我通常#including没有任何路径,所以我习惯将我的子目录(不是那么多)添加到项目设置的include目录中.我有点困惑,因为这些设置可以在项目级别和文件夹级别上进行(我还没有理解值是如何继承的).另外,Properties> C/C++ Build> Settings> GCC C++ Compiler> Include and Properties> C/C++ General> Paths and Symbols> GNU C++有区别吗?
你知道解释这些东西的任何好资源吗?
我刚刚阅读了关于维护我的Android应用程序的状态并偶然发现了onRetainNonConfigurationInstance.但在阅读文档时,我注意到了这句话:
此函数纯粹称为优化,您不能依赖它被调用.
所以我想知道:什么时候使用这种方法真的很有意义.如果我不能依赖它被调用,我还需要另一种机制来传输状态(在我的情况下,这将是一些序列化).因此,除非我遇到任何性能命中,否则我有理由选择onRetainNonConfigurationInstance吗?
如果保证可以使用它,我会喜欢使用它,但如果不是,它似乎没用.
我错过了什么吗?你什么时候使用这种方法?你会如何保持网络连接或类似的东西?
谢谢!
我正在开发一个用于模拟真实世界场景的C++应用程序.基于此模拟,我们的团队将开发,测试和评估在这样一个真实世界中工作的不同算法.
我们需要定义几个场景的可能性(它们可能在一些参数上有所不同,但未来场景可能还需要创建新类的对象)以及维护一组算法的可能性(这也是一组参数但是还要定义要创建的类).参数传递给构造函数中的类.
我想知道哪种是管理所有场景和算法配置的最佳方法.应该很容易让一个开发人员使用"他的"算法处理一个场景,而另一个开发人员使用"他的"不同算法处理另一个场景.尽管如此,参数集可能很大并且应该是"可共享的"(如果我在场景A中为某个算法定义了一组参数,那么应该可以在场景B中使用该算法而无需复制和粘贴).
似乎有两种主要方法可以完成我的任务:
定义可以处理我的要求的配置文件格式.此格式可能是基于XML或自定义的.由于C++中没有类似C#的反射,似乎每次将新算法类添加到项目时都必须更新配置文件解析器(为了将像"MyClass"这样的字符串转换为MyClass的新实例).我可以为每个设置创建一个名称,并将此名称作为命令行参数传递.
用C++代码连接所有内容.我不完全确定如何分离所有不同的创建逻辑,但仍然能够跨场景重用参数.我想我也会尝试给每个设置一个(字符串)名称,并使用此名称通过命令行arg选择设置.
现在我的问题是: - 你有什么看法?我错过了重要的利弊吗? - 我错过了第三种选择吗? - 是否有一种简单的方法来实现配置文件方法,这给我足够的灵活性? - 您如何在seconde方法中组织所有工厂代码?对于像这样的东西,有没有好的C++示例?
非常感谢!
c++ configuration factory configuration-files factory-pattern
在C#和C++中的一些项目之后,我开始使用Java.
我想设计这样的访问者界面:
public interface ActionVisitor<A> {
void visitAction(A action);
}
public interface MySmallActionVisitor
extends ActionVisitor<ActionA>,
ActionVisitor<ActionB>
{
}
public interface MyFullActionVisitor
extends ActionVisitor<ActionA>,
ActionVisitor<ActionB>,ActionVisitor<ActionC>,ActionVisitor<ActionD> //....
{
}
Run Code Online (Sandbox Code Playgroud)
当然,由于类型擦除,这不起作用.(我之所以想要这样的东西,是因为我可以访问不同的Actions组,我会有不同的Visitor接口.)
我想到的唯一解决方案是声明接口
public interface ActionAVisitor {
void visitAction(ActionA action);
}
public interface ActionBVisitor {
void visitAction(ActionB action);
}
//...
Run Code Online (Sandbox Code Playgroud)
然后
public interface MySmallActionVisitor
extends ActionAVisitor, ActionBVisitor
{
}
Run Code Online (Sandbox Code Playgroud)
这可行,但我不想声明所有的ActionXVisitor接口,这是愚蠢的重复和大量的文件......
你有什么想法如何更好地做到这一点?
非常感谢!
我正在使用MATLAB来显示三维数据.我使用GUI来改变视角,缩放和平移.如何存储此视图,然后将其应用于另一个图形(包含或多或少相同的数据)?view给了我一个矩阵,但我怎么能将它应用到另一个数字?
非常感谢!
我遇到了使用队列的代码的意外性能行为.我意识到当队列中有更多元素时,性能会下降.事实证明,使用该size()方法是原因.以下是一些显示问题的代码:
#include <queue>
#include <list>
#include <iostream>
#include "Stopwatch.h"
using namespace std;
struct BigStruct
{
int x[100];
};
int main()
{
CStopwatch queueTestSw;
typedef BigStruct QueueElementType;
typedef std::queue<QueueElementType, std::list<QueueElementType> > QueueType;
//typedef std::queue<QueueElementType > QueueType; //no surprise, this queue is fast and constant
QueueType m_queue;
for (int i=0;i<22000;i++)
m_queue.push(QueueElementType());
CStopwatch sw;
sw.Start();
int dummy;
while (!m_queue.empty())
{
//remove 1000 elements:
for (int i=0;i<1000;i++)
{
m_queue.pop();
}
//call size() 1000 times and see how long it takes
sw = …Run Code Online (Sandbox Code Playgroud) 每当我的项目在Visual Studio中构建时,我想运行代码生成器,即使项目中没有源文件被更改.因此,我希望按照Visual Studio中的说明设置自定义构建步骤:即使项目是最新的,也可以运行C++项目构建后事件.
如何使用CMake创建这样的构建步骤?
我的应用程序的一位用户报告说,当他禁用 Chrome 或安装了旧的 WebView 实现时,他遇到了崩溃。他记录了一个 logcat(见下文),这似乎表明这来自 using,<TextView autoLink="all">因为堆栈跟踪中有一些“linkify”调用。
这是否有记录且正确?我能做些什么来对抗这种情况吗?
01-30 08:19:55.726 22028-22028/? E/WebViewFactory: error instantiating provider
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java:208)
at android.webkit.WebView.getFactory(WebView.java:2530)
at android.webkit.WebView.findAddress(WebView.java:1802)
at android.text.util.Linkify.gatherMapLinks(Linkify.java:562)
at android.text.util.Linkify.addLinks(Linkify.java:260)
at android.text.util.Linkify.addLinks(Linkify.java:226)
at android.widget.TextView.setText(TextView.java:5330)
at android.widget.TextView.setText(TextView.java:5250)
at android.widget.TextView.<init>(TextView.java:1626)
at android.widget.TextView.<init>(TextView.java:820)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:44)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:40)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:806)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:836)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) …Run Code Online (Sandbox Code Playgroud) 我有两个活动,A和B. A调用了B startActivityForResult().B有主题@android:style/Theme.Dialog.
因此,B显示在"A"之上,但A仍然可见(因为B是对话框).
当两个活动都启动时,我通过切换到另一个任务并返回来强制重新创建(我在android开发人员设置中启用了"不要保持活动"选项.当我返回到我的任务时,我看到在A和B上调用OnCreate .)
当我点击活动B按钮,它调用setResult()和finish(),但onActivityResult() 不叫上.
问题没有出现
要么
我在使用Android 9的Google Pixel上测试了这个.
这是预期的行为还是Android中的错误?
这是我用来测试它的代码(Xamarin Android):
[Activity(Label = "@string/app_name")]
public class ActivityA : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
Kp2aLog.Log("OnCreate A");
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);
{
FindViewById<Button>(Resource.Id.btn_yubichall).Text = "Start B";
FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{
var chalIntent = new Intent(this, typeof(ActivityB));
StartActivityForResult(chalIntent, 123);
};
}
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, …Run Code Online (Sandbox Code Playgroud) c++ ×4
android ×3
java ×2
cmake ×1
coding-style ×1
dialog ×1
eclipse-cdt ×1
factory ×1
generics ×1
include ×1
matlab ×1
performance ×1
plot ×1
queue ×1
state ×1
stl ×1
templates ×1
type-erasure ×1