小编Kir*_*rov的帖子

C++构造函数默认值头文件

我正在尝试使用默认值创建构造函数.复杂性来自于为类使用单独的头文件和代码文件.我有一个包含以下内容的头文件:

class foo {
    bool dbg;
    public:
        foo(bool debug = false);
}
Run Code Online (Sandbox Code Playgroud)

一个代码文件包含:

foo::foo(bool debug = false) {
    dbg = debug;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试用g ++(即g++ -c foo.cc)编译时,它会给出一个错误:

foo.cc:373:65: error: default argument given for parameter 1 of ‘foo::foo(bool)’
foo.h:66:4: error: after previous specification in ‘foo::foo(bool)’
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c++ constructor class default-value

9
推荐指数
2
解决办法
9370
查看次数

完全定制Qt创建者编码风格?

有没有办法在QT创建者中完全自定义首选编码风格?

这就是我的例子(我将直接使用来自Qt creator设置的示例代码中的一部分):

class Complex
{
public:
    Complex(double re, double im)
        : _re(re), _im(im)
    {}
    double modulus() const
    {
        return sqrt(_re * _re + _im * _im);
    }
private:
    double _re;
    double _im;
};
Run Code Online (Sandbox Code Playgroud)

我希望这成为:

class complex // <- lower latter
{
public:
    complex( double re, double im ) // <- spaces after/before ()
    : // <- new line
         _re( re ), // <- spaces after/before ()
        _im( im ) // <- new line and spaces after/before () …
Run Code Online (Sandbox Code Playgroud)

c++ qt coding-style qt-creator

9
推荐指数
2
解决办法
1万
查看次数

用于反汇编C++可执行文件的最佳Linux工具

哪种工具最适合反汇编C++可执行文件?我正在寻找像OllyDbg这样的东西,但是对于Linux.

编辑:对不起,忘了告诉我我也想调试,而不仅仅是看到asm代码.

编辑2:"最好的"我的意思是 - "最好的Windows是OllyDbg - 可以看到asm代码,可以调试,它是用户友好和非常强大.哪一个最适合Linux".

c++ linux debugging disassembly

8
推荐指数
1
解决办法
7090
查看次数

如何使用C API为MySQL查询设置超时

我知道这里有很多类似的问题,当我谷歌时它也有很多结果,但没有一个能回答我的问题.我读了这个,这个,这个这个,但它们都不适合我.我不谈任何锁,我不想使用MySQL c ++连接器,只是C API.

另外,这里非常重要:我在LINUX上这样做.我为什么提这个?因为在mysql_options的文档中:

MYSQL_OPT_READ_TIMEOUT - ...This option works only for 
TCP/IP connections and, prior to MySQL 5.0.25, only for Windows.

MYSQL_OPT_WRITE_TIMEOUT- ... This option works only for 
TCP/IP connections and, prior to MySQL 5.0.25, only for Windows

那么,有没有办法为5.0.25之前的版本设置查询超时?

我的MySQL版本:

[root@xxx kiril]# mysql --version
mysql  Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (i686) using readline 5.0

编辑:至少,有没有办法取消查询?我可以启动一个计时器作为不同的线程,但当它到期..我可以以某种方式取消查询?

c c++ mysql api

8
推荐指数
1
解决办法
4867
查看次数

需要一些帮助来理解搜索算法(A*,IDA*,DFS,BFS,IDDFS等)

我在理解用于AI(人工智能)的一些搜索算法时遇到了一些麻烦.

  • A*IDA*(Iterative Deeping A Star)之间的确切区别是什么?只是启发式功能?如果是这样,我仍然无法想象IDA*如何运作..:/
  • IDA*BFS(广度优先搜索)(扩展时的深度只有1级,我的意思是-移动一个级别只有一个"下",有什么区别IDA*BFS)
  • IDDFS(迭代式进一步深化闽台深度优先搜索)一样的IDA*,除了启发函数(即相当于0 IDDFS)
  • IDDFS究竟是什么 - 向下移动一级,然后使用DFS(深度优先搜索)?如果是这样,这样很多状态的计算(扩展)远远超过一些......或者就像这样 - 使用具有特定深度的DFS,然后存储"叶子"(最后扩展的节点),并迭代它们使用再次DFS(实际上,这是BFS?)
  • " 迭代 "来自哪里?正如我所见,IDDFS根本不是迭代的,它仍然是递归的,只是混合了BFSDFS?或者我错了?或者这个" 迭代 "与递归的相反无关?
  • IDA*的 " 迭代 "是什么?

请你提供一些例子吗?我整天都在阅读这些算法,我知道它们的优点和缺点,复杂性等等,但我找不到任何好的例子(除了A*;我知道BFS和DFS,其他人打扰我).我在不同的地方发现了一些IDA*的伪代码,但它们都完全不同.

例子是了解算法的最好方法..但我找不到.即使在TopCoder中,我也没有找到任何有关IDA*的信息.

我已经阅读了维基文章,我正在寻找新的东西(:

非常感谢!


编辑: 这里有一些很好的文章,但它们太理论化了.没有例子,没有任何具体的东西.但仍然非常有用.我推荐他们(=

algorithm search artificial-intelligence belongs-to

8
推荐指数
1
解决办法
4703
查看次数

使用AF_UNSPEC会有哪些缺点/风险?

Beej的网络编程指南

您可以强制它在ai_family字段中使用IPv4或IPv6,或将其保留为AF_UNSPEC以使用任何内容.这很酷,因为您的代码可以与IP版本无关.

正如标题所说 - 总是使用的缺点(或风险,如果有的话)AF_UNSPEC,而不是指定IPv4或IPv6?

或者只是出于一个原因 - 如果指定了版本,这将保证只支持此版本吗?


一点背景 - 我考虑在客户端 - 服务器(C++)应用程序中添加对IPv6的支持,并且应该支持这两个版本.所以我想知道它是否可以使用,AF_UNSPEC或者最好"识别"字符串中的地址并使用AF_INET6AF_INET取决于地址.

c c++ unix sockets network-programming

8
推荐指数
1
解决办法
8962
查看次数

inet_ntoa的分段错误

    #include <stdio.h> 
    #include <string.h> /* for strncpy */ 
    #include <sys/types.h> 
    #include <sys/socket.h> 
    #include <sys/ioctl.h> 
    #include <netinet/in.h> 
    #include <net/if.h> 

    int 
    main() 
    { 
     int fd;  
     struct ifreq ifr; 

     fd = socket(AF_INET, SOCK_DGRAM, 0);  

     /* I want to get an IPv4 IP address */ 
     ifr.ifr_addr.sa_family = AF_INET; 

     /* I want IP address attached to "eth0" */ 
     strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1); 

     ioctl(fd, SIOCGIFADDR, &ifr); 

     close(fd); 

     /* display result */ 
     char* ipaddr; 
     ipaddr = inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr); 
     printf("%s\n", ipaddr); 

     return 0; 
    } 
Run Code Online (Sandbox Code Playgroud)

对于这一行:

     ipaddr = inet_ntoa(((struct …
Run Code Online (Sandbox Code Playgroud)

c

8
推荐指数
1
解决办法
7663
查看次数

在源文件中放置模板成员函数(without default body)的特化定义是否安全?

这就是我的意思:

// test.h
class cls
{
public:
    template< typename T >
    void f( T t );
};
Run Code Online (Sandbox Code Playgroud)

-

// test.cpp
template<>
void cls::f( const char* )
{
}
Run Code Online (Sandbox Code Playgroud)

-

// main.cpp
int main()
{
    cls c;

    double x = .0;
    c.f( x ); // gives EXPECTED undefined reference (linker error)

    const char* asd = "ads";
    c.f( asd ); // works as expected, NO errors

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这完全没问题吧?

我开始怀疑这一点,因为我只是碰到了specialization of '...' after instantiation错误,这对我来说是新的.所以,我"解决"这个错误,现在一切似乎工作正常,但仍然..

这是明确定义的行为吗?


编辑:对于非成员模板函数(前向声明的非成员模板函数)也是如此.

c++ templates member-functions template-specialization default-implementation

8
推荐指数
2
解决办法
326
查看次数

如何在c ++代码中链接STL?

我在源文件sql_parse.cc中写了一些代码MySql 5.5.7rc.我使用过vector,allocator等等,但编译器没有与标准模板库(STL)链接.任何人都可以建议我该怎么办?

这是错误消息:

libsql.a(sql_parse.cc.o): In function `std::vector<std::basic_string<char,  
std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > > >::push_back(std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&)':
sql_parse.cc:(.text._ZNSt6vectorISsSaISsEE9push_backERKSs[std::vector<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > > >::push_back(std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&)]+0x74): undefined reference to 
`std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 
std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > 
>::_M_insert_aux(__gnu_cxx::__normal_iterator<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&)'

collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

c++ stl

7
推荐指数
1
解决办法
1万
查看次数

在map或unordered_map中是必需的insert()吗?

我看到很多将项添加到a mapunordered_mapvia 的示例operator[],如下所示:

int main() {
    unordered_map <string, int> m;
    m["foo"] = 42;
    cout << m["foo"] << endl;
}
Run Code Online (Sandbox Code Playgroud)

是否有任何理由使用insert成员函数?看起来他们都做同样的事情.

c++

7
推荐指数
1
解决办法
7635
查看次数