我正在尝试使用默认值创建构造函数.复杂性来自于为类使用单独的头文件和代码文件.我有一个包含以下内容的头文件:
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)
我究竟做错了什么?
有没有办法在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++可执行文件?我正在寻找像OllyDbg这样的东西,但是对于Linux.
编辑:对不起,忘了告诉我我也想调试,而不仅仅是看到asm代码.
编辑2:"最好的"我的意思是 - "最好的Windows是OllyDbg - 可以看到asm代码,可以调试,它是用户友好和非常强大.哪一个最适合Linux".
我知道这里有很多类似的问题,当我谷歌时它也有很多结果,但没有一个能回答我的问题.我读了这个,这个,这个和这个,但它们都不适合我.我不谈任何锁,我不想使用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
编辑:至少,有没有办法取消查询?我可以启动一个计时器作为不同的线程,但当它到期..我可以以某种方式取消查询?
我在理解用于AI(人工智能)的一些搜索算法时遇到了一些麻烦.
请你提供一些例子吗?我整天都在阅读这些算法,我知道它们的优点和缺点,复杂性等等,但我找不到任何好的例子(除了A*;我知道BFS和DFS,其他人打扰我).我在不同的地方发现了一些IDA*的伪代码,但它们都完全不同.
例子是了解算法的最好方法..但我找不到.即使在TopCoder中,我也没有找到任何有关IDA*的信息.
我已经阅读了维基文章,我正在寻找新的东西(:
非常感谢!
编辑: 这里有一些很好的文章,但它们太理论化了.没有例子,没有任何具体的东西.但仍然非常有用.我推荐他们(=
您可以强制它在ai_family字段中使用IPv4或IPv6,或将其保留为AF_UNSPEC以使用任何内容.这很酷,因为您的代码可以与IP版本无关.
正如标题所说 - 总是使用的缺点(或风险,如果有的话)AF_UNSPEC,而不是指定IPv4或IPv6?
或者只是出于一个原因 - 如果指定了版本,这将保证只支持此版本吗?
一点背景 - 我考虑在客户端 - 服务器(C++)应用程序中添加对IPv6的支持,并且应该支持这两个版本.所以我想知道它是否可以使用,AF_UNSPEC或者最好"识别"字符串中的地址并使用AF_INET6或AF_INET取决于地址.
#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) 这就是我的意思:
// 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
我在源文件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) 我看到很多将项添加到a map或unordered_mapvia 的示例operator[],如下所示:
int main() {
unordered_map <string, int> m;
m["foo"] = 42;
cout << m["foo"] << endl;
}
Run Code Online (Sandbox Code Playgroud)
是否有任何理由使用insert成员函数?看起来他们都做同样的事情.
c++ ×8
c ×3
algorithm ×1
api ×1
belongs-to ×1
class ×1
coding-style ×1
constructor ×1
debugging ×1
disassembly ×1
linux ×1
mysql ×1
qt ×1
qt-creator ×1
search ×1
sockets ×1
stl ×1
templates ×1
unix ×1