我不确定要作为默认值返回什么?
myDrugs是一个私人vector<Drug*>容器
Drug* DrugDealer::getFirstDrugInSack(DrugType drugtobuy)
{
for (int i = 0; i < myDrugs.size(); i++)
{
if (myDrugs[i]->getType() == drugtobuy)
return myDrugs[i];
}
return 0; // is this right?
}
Run Code Online (Sandbox Code Playgroud)
所以我会称之为:
Drug *d = DrugDealer->getFirstDrugInSack(DrugType::Weed);
if (d != 0)
// do something
else
// onose?
Run Code Online (Sandbox Code Playgroud)
或者有更好的方法吗?
使用.Net 3.5中的System.Speech.Synthesis.SpeechSynthesizer类,SpeakProgressEventArgs的AudioPosition属性似乎不准确.
以下代码生成以下输出:
码:
using System;
using System.Speech.Synthesis;
using System.Threading;
namespace SpeechTest
{
class Program
{
static ManualResetEvent speechDoneEvent = new ManualResetEvent(false);
static void Main(string[] args)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synthesizer_SpeakProgress);
synthesizer.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synthesizer_SpeakCompleted);
synthesizer.SetOutputToWaveFile("Test.wav");
synthesizer.SpeakAsync("This holiday season, support the music you love by shopping at Made in Washington, online and at one of five local stores. Made in Washington chocolates, bountiful gift baskets and ornaments are the perfect holiday gifts for family, friends …Run Code Online (Sandbox Code Playgroud) 似乎jQuery和MS AJAX以及YSlow和Google Page Speed等工具的普及使得内容交付网络(CDN)上托管了通用组件.
那么哪些CDN存在以及它们服务的文件是什么?
WPF DragDrop.DoDragDrop方法DragSource作为其第一个参数.
有没有办法可以DragSource在OnDrop其他拖放事件中获取此对象?
我有4组值:y1,y2,y3,y4和一组x.y值具有不同的范围,我需要将它们绘制为单独的曲线,在y轴上具有单独的值集.
简单来说,我需要3个具有不同值(比例)的y轴,以便在同一个图上绘图.
任何帮助表示赞赏,或提示在哪里寻找.
我对C/C++中的数组和指针有一个基本的问题.
说我有:
Foo* fooPtrArray[4];
Run Code Online (Sandbox Code Playgroud)
如何传入fooPtrArray函数?我试过了:
int getResult(Foo** fooPtrArray){} // failed
int getResult(Foo* fooPtrArray[]){} // failed
Run Code Online (Sandbox Code Playgroud)
我该如何处理指针数组?
编辑: 我曾经认为错误消息来自传递错误的指针数组,但是从所有响应中,我意识到它是另一回事......(指针赋值)
Error msg:
Description Resource Path Location Type incompatible types in assignment of
`Foo**' to `Foo*[4]' tryPointers.cpp tryPointers line 21 C/C++ Problem
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它说:Foo**到Foo*[4].如果作为函数参数彼此互换,为什么在赋值期间,它会给出编译错误?
我尝试用最少的代码复制错误消息,如下所示:
#include <iostream>
using namespace std;
struct Foo
{
int id;
};
void getResult(Foo** fooPtrArray)
{
cout << "I am in getResult" << endl;
Foo* fooPtrArray1[4];
fooPtrArray1 = fooPtrArray;
}
int main()
{
Foo* fooPtrArray[4];
getResult(fooPtrArray);
}
Run Code Online (Sandbox Code Playgroud) '{'之前的预期不合格标识
我的代码在哪里出错?感谢大家!
#include <iostream>
using std::cout;
using std::endl;
//function prototypes
void findsmallest (int[], int &);
void findsmallest (int scores [], int & min);
int main()
{
//declare variables
int smallest = 0;
int scores[20] = { 90, 54, 23, 75, 67,
89, 99, 100, 34, 99,
97, 76, 73, 72, 56,
73, 72, 65, 86, 90 };
findsmallest(scores, smallest);
return 0;
//call function find smallest
findsmallest (scores, smallest);
cout << "Minimum value in the array is " << smallest << …Run Code Online (Sandbox Code Playgroud) 假设我需要从1000000个随机数值序列中检索中值.
如果使用任何但是 STL ::名单,我没有(内置)的排序方式为中值计算序列.
如果使用STL :: list,我不能随机访问值来检索排序序列的中间(中位数).
是自己实现排序和使用例如STL :: vector更好,还是使用STL :: list并使用STL :: list :: iterator for-loop-walk到中值?后者似乎不那么开销,但也感觉更难看..
或者我有更多更好的选择吗?
我只是对如何sleep(time in ms)在C库中实现或基本上在操作系统级别实现...
我猜...
有线索吗?可能C库的源代码可以解释一下吗?我并不太关注"C"是如何实现的......我只是想知道"sleep()"函数是如何实现的.
假设我在Windows(Visual Studio 2008)下启动了一个C#项目,我想切换到Mono.我是否必须重新编译项目使用的所有依赖项,例如NHibernate和出现的每个外部依赖项?
注1:我问这个问题的原因是我在Ubuntu 9.10上使用MonoDevelop构建了一个项目,一切都像魅力一样但是当我尝试调试运行一些用NUnit编写的测试时,一切都冻结了.我必须取消正在运行的测试以使MonoDevelop备份,并且没有明确的堆栈跟踪或提示我可以用来查找问题.所以我可能需要在Mono/Linux下编译NHibernate(以及其他依赖项).