哪种编程领域最适合哪种语言?
我喜欢C++和C#,但我更喜欢使用C#,因为.NET.
我的问题是你什么时候使用C++?什么时候使用C#?
因此,如果您为公司提供财务申请,您将使用C#?(在不下载第三方库的情况下设计表单并连接到数据库很容易,如果你制作高级算法,你会使用C++来提高速度吗?
这是我的想法.我刚观看了视频@ http://www.academicearth.org,似乎大学更喜欢使用C++进行机器学习.
你们怎么看待它?什么是行业观点.
我已经阅读了许多关于引用和指针之间的区别以及何时使用哪些内容的讨论.他们似乎都从分析两者的行为中得出了他们的结论.
但是我仍然想知道语言设计者的想法.这个设计的主要动机是什么?在什么情况下它打算使用?也许答案已经包含在我提到的讨论中,但我想知道哪些是真实的.
PS只要指针在C++中,引用是否有历史记录?它起源于一开始还是作为某些情况的补丁?非常感谢.
也许这个问题很简单,但第二次考虑它我想知道如何以正确的方式做到以下几点:
std::vector<K> v = ...;
for(T i=0; i<v.size(); ++i) {
const K& t = v[i];
// use t *and i*
}
Run Code Online (Sandbox Code Playgroud)
应该T是什么类型的?int,unsigned int,int32_t,size_t(这将是的类型v.size())或任何其他建议?请尝试考虑可移植性,错误倾向和性能,并在您的答案中保持客观.
编辑:我没有选择迭代器,因为它也想明确使用索引号.
现在我尝试使用boost bind&mem_fn.但是绑定重载函数存在问题.如何解决以下代码的编译错误?
boost::function< void( IF_MAP::iterator ) > bmf = std::mem_fun1< void, IF_MAP, IF_MAP::iterator >( &IF_MAP::erase );
boost::function< void( IF_MAP::iterator ) > bmf = boost::mem_fn< void, IF_MAP, IF_MAP::iterator >( &IF_MAP::erase );
Run Code Online (Sandbox Code Playgroud)
主要目的是编制以下代码
IF_MAP M;
boost::function< void( IF_MAP::iterator ) > bmf = boost::bind(
boost::mem_fn< void, IF_MAP, IF_MAP::iterator >( &IF_MAP::erase ),
&M, _1 );
M.insert( IF_MAP::value_type( 1, 1.f ) ); M.insert( IF_MAP::value_type( 2, 2.f ) );
bmf( 2 );
Run Code Online (Sandbox Code Playgroud)
编译错误消息是这样的......
错误C2665:'boost :: mem_fn':2个重载中没有一个可以转换所有的参数类型可能是'boost :: _ mfi :: mf1 boost :: mem_fn …
我正在阅读关于自修改代码的密码破解者期刊文章,并且有以下代码片段:
void Demo(int (*_printf) (const char *,...))
{
_printf("Hello, OSIX!n");
return;
}
int main(int argc, char* argv[])
{
char buff[1000];
int (*_printf) (const char *,...);
int (*_main) (int, char **);
void (*_Demo) (int (*) (const char *,...));
_printf=printf;
int func_len = (unsigned int) _main - (unsigned int) _Demo;
for (int a=0; a<func_len; a++)
buff[a] = ((char *) _Demo)[a];
_Demo = (void (*) (int (*) (const char *,...))) &buff[0];
_Demo(_printf);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这段代码应该在堆栈上执行Demo().我理解大部分代码,但是他们分配'func_len'的部分让我困惑.据我所知,他们从另一个随机指针地址中减去一个随机指针地址.
有人在意解释?
我最近问了一个问题,我正在让MIT Kerberos与微软的LSA凭证缓存很好地协同工作.
我被告知设置注册表项AllowTGTSessionKey应该可以解决问题.
但是,我仍然遇到问题,现在我挖得更深了.
运行klist tgt(使用Microsoft提供的klist \windows\system32),它在所有其他输出中显示:
Session Key : KeyType 0x17 - RSADSI RC4-HMAC(NT)
: KeyLength 16 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Run Code Online (Sandbox Code Playgroud)
因此,会话密钥仍然被消隐,即使这是上面提到的注册表项应该解决的问题.
那么哪些其他条件可能导致会话密钥被消除?
我现在尝试了各种各样的用户帐户(域管理员,域用户,启用和不启用UAC),似乎没有任何区别.
那么,有谁知道问题可能是什么?或者知道一个解决方案(和/或丑陋的hacky解决方法)
我试图在我的单吨类的静态功能之一上实现Mutex锁.但是得到这个错误:
$error:‘m_Mutex’ declared as reference but not initialized
$warning:warning: unused variable ‘m_Mutex’
Run Code Online (Sandbox Code Playgroud)
这是我的代码片段.
======== Commondefines.h ==========
/**
*@class LockBlock
*This class is used to provide Mutex Lock on thread.
*/
class LockBlock
{
public:
LockBlock(pthread_mutex_t *mutex)
{
lockMutex = mutex;
pthread_mutex_lock(lockMutex);
};
~LockBlock()
{
pthread_mutex_unlock(lockMutex);
lockMutex = NULL;
}
private:
pthread_mutex_t *lockMutex;
};
Run Code Online (Sandbox Code Playgroud)
======== MutexImplenation.h ======
#include "CommonDefines.h"
class MutexImplementation
{
private:
static pthread_mutex_t m_Mutex ;
public:
static void commonFunction();
};
Run Code Online (Sandbox Code Playgroud)
==== MutexImplementation.cpp ==========
// Initialize static member of class. …Run Code Online (Sandbox Code Playgroud) 作为一个新手,我正在尝试使用list-class在C++中实现排序功能.但是,运行代码我得到的错误是列表迭代器不可递增...但是它似乎不太可能,因为它应该是可递增的!
码:
void shuffle (list<int> &list1)
{
list<int> smaller;
list<int> larger;
if (list1.size() > 1)
{
list<int>::iterator it;
//int it;
int x = list1.front();
for (it = list1.begin(); it != list1.end(); it++)
{
if(*it <= x)
{
smaller.push_front(*it);
list1.pop_front();
}
else
{
larger.push_back(*it);
list1.pop_front();
}
shuffle (smaller);
shuffle (larger);
}
}
else
{
print(smaller);
print(larger);
//cout << "No sorting needed! The list still looks like: ";
//print(list1);
}
print(smaller);
print(larger);
}
Run Code Online (Sandbox Code Playgroud)
我在de CPP文件中主要实现了这个功能.
有人有什么建议吗?
以下是由于序列点规则导致未定义行为的两个常见问题:
a[i] = i++; //has a read and write between sequence points
i = i++; //2 writes between sequence points
Run Code Online (Sandbox Code Playgroud)
您在序列点方面遇到的其他事情是什么?
当编译器无法警告我们时,很难找到这些问题.
我在Windows Vista Business x64,四核机器,8gb ram上使用Visual Studio 2008 SP1运行以下代码.
如果我构建一个发布版本,并从命令行运行它,它报告31ms.如果我然后从IDE启动它,使用F5,它报告23353ms.
以下是时间:(所有Win32版本)
码:
#include <windows.h>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int runIntersectionTestAlgo()
{
set<int> set1;
set<int> set2;
set<int> intersection;
// Create 100,000 values for set1
for ( int i = 0; i < 100000; i++ )
{
int value = 1000000000 + i;
set1.insert(value);
}
// Create 1,000 values for set2
for ( int i = 0; i < 1000; i++ )
{
int …Run Code Online (Sandbox Code Playgroud)