是否有任何易于使用的,高层次的类或库,让你互动VARIANT
的可视化(C S)++?
更具体地讲,我想POD类型(例如之间的转换double
,long
),字符串(如CString
),和容器(如std::vector
)和VARIANT
秒.例如:
long val = 42;
VARIANT var;
if (ToVariant(val, var)) ... // tries to convert long -> VARIANT
comObjPtr->someFunc(var);
std::vector<double> vec;
VARIANT var = comObjPtr->otherFunc();
if (FromVariant(var, vec)) ... // tries VARIANT -> std::vector<double>
Run Code Online (Sandbox Code Playgroud)
我(天真地?)假设与COM一起工作的人一直这样做,所以最有可能是一个方便的库来处理各种转换.但是我能找到的所有内容都是各种各样的包装类,每个类都转换为几种类型:
有没有简单的方法 - 没有切换到Visual Basic - 以避免这种笨拙的内存管理和按位VT_ARRAY | VT_I4
代码的噩梦?
相关问题: …
在派生类的析构函数执行之后但在基类的析构函数执行之前,C++标准对于对象状态的保证是什么?(这是派生类的子对象的析构函数被调用的时间.)
#include <string>
struct Base;
struct Member {
Member(Base *b);
~Member();
Base *b_;
};
struct Base {
virtual void f() {}
virtual ~Base() {}
};
struct Derived : Base {
Derived() : m(this) {}
virtual ~Derived() {}
virtual void f() {}
std::string s;
Member m;
};
Member::Member(Base *b) : b_(b) {}
Member::~Member() {
// At this point, ~Derived has finished -- can we use b_ as a
// Derived* object (i.e. call Derived::f or access Derived::s)?
b_->f();
} …
Run Code Online (Sandbox Code Playgroud) 我正在学习C++并且遇到了链接器显然使用的那些*.lib文件.我不得不为OpenGL设置一些额外的依赖项.
或者它们只是与*.obj文件类似的可重定位对象代码?
如果我构造一个二进制搜索树,按顺序添加以下值:
10, 7, 16, 12, 5, 11, 2, 20, 1, 14
Run Code Online (Sandbox Code Playgroud)
我得到一个高度为5的树.是否有一个方法(除了试验和错误)我可以用来确定一个整数的排序,它将创建一个高度为4的树?
我是C++初学者,下面的程序非常简单,但我不知道为什么当输入"EXIT"时,程序终止,虽然它应该打印出之前输入的名字!
这是代码:
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main()
{
set <string> myset;
set <string> :: const_iterator it;
it = myset.begin();
string In;
int i=1;
string exit("EXIT");
cout << "Enter EXIT to print names." << endl;
while(1)
{
cout << "Enter name " << i << ": " ;
cin >> In;
if( In == exit)
break;
myset.insert(In);
In.clear();
i++;
}
while( it != myset.end())
{
cout << *it << " " ;
it ++ ; …
Run Code Online (Sandbox Code Playgroud) 我想让UICollectionView对特定项目进行动画滚动.
这大部分时间都有效,但偶尔我尝试滚动的项目最终不会被显示.
- (void)onClick {
// (Possibly recompute the _items array.)
NSInteger target_idx = // (...some valid index of _items)
NSIndexPath *item_idx = [NSIndexPath indexPathForItem:target_idx inSection:0];
[self scrollToItem:item_idx];
}
- (void)scrollToItem:(NSIndexPath*)item_idx {
// Make sure our view is up-to-date with the data we want to show.
NSInteger num_items = [self.collection_view numberOfItemsInSection:0];
if (num_items != _items.count) {
[self.collection_view reloadData];
}
[self.collection_view
scrollToItemAtIndexPath:item_idx
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
self.collection_view
是一个UICollectionView,由一行项目组成,启用标准流程布局和水平滚动.reloadData
在滚动之前调用,因为_items
自UICollectionView上次显示它以来可能已经改变了.animated:NO
那么一切都按预期工作. …我使用va_list时遇到问题.以下代码适用于int:
main() {
int f1=1;
float** m = function(n,f1);
}
float** function(int n,...) {
va_list mem_list;
va_start(mem_list, n);
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
//m[i][j]=va_arg(mem_list,float);
int f = va_arg(mem_list,int);
printf("%i \n",f);
}
}
va_end(mem_list);
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我改为浮动即
float f1=1.0;
float f = va_arg(mem_list,float);
printf("%f \n",f);
Run Code Online (Sandbox Code Playgroud)
它不返回正确的值(值为0.00000).我对发生的事情感到非常困惑.
如果可以在C#中使用TimesSpan打印microsencods,请再次问我的问题.
我有下一个例子:
DateTime startTime = DateTime.Now;
..../some code
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startTime);
Label3.Text=(totalTimeTaken.Milliseconds).ToString();
Run Code Online (Sandbox Code Playgroud)
这段代码允许我以毫秒显示,但我需要显示微秒是否有办法将其更改为微秒或我是否必须使用其他东西?
我必须编辑我的问题:我的目标是测量2 DateTime之间花费的时间,因为它只是很少的代码行,毫秒不会削减它,这就是我需要微秒的原因.
我正在阅读 XOR 链表,我想到了一个问题,在我Is it possible to have a circular XOR linked list?
看来,即使我们以某种方式构建了这样一个列表,也不可能在给定列表头节点的情况下遍历它。例如 - 让链表包含 3 个节点:A、B 和 C。
|
v
A ---> B ---> C
A->xor = B ^ C
B->xor = A ^ C
C->xor = A ^ B
Run Code Online (Sandbox Code Playgroud)
由于我们已经给出head
了列表,即A
在这种情况下,我们将无法向前或向后移动,因为我们必须至少知道B
或C
中的一个才能移动。由于我们无法遍历它,因此我们也无法构建它。
我的想法正确吗?或者我错过了什么?
char* func( char* a, const char* b )
{
while( *a )
{
char *s = a, *t = b;
while( (*s++ == *t++) && *s && *t );
if( *t == 0 )
return a;
a++;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编写上面的代码是为了在字符串"a"中搜索字符串"b"的第一个实例.
上述程序有问题吗?
有没有办法提高它的效率?
我有3个文件Test.h,Test.cpp和main.cpp
Test.h
#ifndef Test_H
#define Test_H
namespace v
{
int g = 9;;
}
class namespce
{
public:
namespce(void);
public:
~namespce(void);
};
#endif
Run Code Online (Sandbox Code Playgroud)
TEST.CPP
#include "Test.h"
namespce::namespce(void)
{
}
namespce::~namespce(void)
{
}
Run Code Online (Sandbox Code Playgroud)
Main.cpp的
#include <iostream>
using namespace std;
#include "Test.h"
//#include "namespce.h"
int main ()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在建设过程中出现以下错误..
1>namespce.obj : error LNK2005: "int v::g" (?g@v@@3HA) already defined in main.obj
1>C:\Users\E543925\Documents\Visual Studio 2005\Projects\viku\Debug\viku.exe : fatal error LNK1169: one or more multiply defined symbols found
Run Code Online (Sandbox Code Playgroud)
请尽快帮助..
我在主函数中使用它时,swap(string1,string2)将轻松交换两个字符串值,但如果我在另一个函数中使用它并从main函数调用它将无法工作!
这工作:
int main()
{
string name1="A",name2="B";
swap(name1,name2);
}
Run Code Online (Sandbox Code Playgroud)
但这个没有:
string name1="A",name2="B"; // Global Here
void exchange (string one,string two)
{
swap(one,two);
}
int main()
{
exchange(name1,name2);
}
Run Code Online (Sandbox Code Playgroud)
问题出在哪儿?
使用双I型立方样条插值算法.这项工作似乎是成功的,但是当计算非常小的值时,相对误差约为6%.
双数据类型是否足以进行准确的科学数值分析?
c++ ×8
algorithm ×2
c ×2
animated ×1
binary-tree ×1
c# ×1
datetime ×1
destructor ×1
ios ×1
linked-list ×1
objective-c ×1
scroll ×1
timespan ×1
variant ×1
visual-c++ ×1
windows ×1