小编pmr*_*pmr的帖子

需要在导出构建树中导出 CMake 目标

我有一个 CMake 项目,其中包含一个也可以用作独立 CMake 构建的Foobar子目录。examples为此,该子目录执行find_package(Foobar)并使用导出的目标。Foobar提供FoobarConfig.cmakeFoobarConfigVersion.cmake和 a FoobarExports.cmake,并且可以在没有 FindModule 的情况下使用。

代码大致如下:

### Top-Level CMakeLists.txt ###
cmake_minimum_required(VERSION 3.0.0)
project(Foobar)

add_library(X SHARED ${my_sources})
install(TARGETS X EXPORT FoobarExports
  LIBRARY DESTINATION ${my_install_destination})
install(EXPORT FoobarExports DESTINATION ${my_install_destination})
# Create the FoobarExports.cmake for the local build tree
export(EXPORT FoobarExports) # the problematic command

# Setup FoobarConfig.cmake etc
# FoobarConfig.cmake includes FoobarExports.cmake
# ...

# Force find_package to FOOBAR_DIR
option(BUILD_EXAMPLES "Build examples" ON)
if(BUILD_EXAMPLES)
  set(FOOBAR_DIR …
Run Code Online (Sandbox Code Playgroud)

cmake build-system

5
推荐指数
1
解决办法
1261
查看次数

为什么会发生此转换?

#include<iostream>

using namespace std;

class test
{
  int a, b;
public:

  test() {
    a=4; b=5;
  }

  test(int i,int j=0) {
    a=i; b=j;
  }

  test operator +(test c) {
     test temp;
     temp.a=a+c.a;
     temp.b=b+c.b;
     return temp;
  }

  void print() {
    cout << a << b;
  }
};

int main() {
  test t1, t2(2,3), t3;
  t3 = t1+2;
  t3.print();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译器如何能接受像一份声明t3=t1+2;,其中2没有一个对象?

c++ operator-overloading visual-c++

4
推荐指数
1
解决办法
96
查看次数

QObject :: moveToThread并在该线程内执行成员函数

如果将类型的对象QObject移动到一个线程QObject::moveToThread,则该对象接收的所有信号都在该线程内处理.但是,如果直接object->theSlot()调用一个槽(),那么该调用仍会阻塞.在线程内执行该调用并将控制立即返回到调用线程的正常方法是什么?黑客与QTimer不计.如果所有其他连接都失败,设置单一用途连接并再次删除它可能会被视为一种解决方案.

qt multithreading qt4

4
推荐指数
1
解决办法
1219
查看次数

没有释放记忆

我无法真正理解为什么自由进程会返回错误.我在C中得到了这段代码:

int LuffarschackStart(void)
{
/* to avoid the program from closing */
char readEnd;
int i = 0;    

board_type *board = malloc(sizeof(square_type));
if (board == NULL)
{
    printf("Could not allocate the memory needed...");
    scanf("%c", &readEnd);         
    return 0;
}

for(i = 0; i < 9; i = i + 1)
    board->square[i].piece_type = NO_PIECE;

board_play_game(board);    

free(board);
printf("Press any key and enter to quit the program...");
scanf("%c", &readEnd);         
return 0;
}
Run Code Online (Sandbox Code Playgroud)

我分配的板结构如下所示:

typedef struct
{
    /* flag to indicate if a square is …
Run Code Online (Sandbox Code Playgroud)

c memory malloc free

3
推荐指数
1
解决办法
579
查看次数

如何简化这种二叉树遍历功能?

template<typename T>
void traverse_binary_tree(BinaryTreeNode<T>* root,int order = 0)// 0:pre, 1:in , 2:post
{
    if( root == NULL ) return;

    if(order == 0) cout << root->data << " ";

    traverse_binary_tree(root->left,order);

    if(order == 1) cout << root->data << " ";

    traverse_binary_tree(root->right,order);

    if(order == 2) cout << root->data << " ";

}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来编写这个功能?

c++ algorithm binary-tree

3
推荐指数
1
解决办法
1205
查看次数

Liferay Web内容portlet中使用了哪种技术?

为了创建Web内容,使用Web内容portlet.这个portlet背后有什么技术?用于开发此portlet的是什么?JSP,JSF,Struts,Icefaces还是其他任何东西?

此外,是否有单独下载它的链接.

portlet liferay webcontent

3
推荐指数
1
解决办法
1072
查看次数

为浮动类型重载operator%

我试图重载运算符%因为你不能在双类型上使用模数,

float a = 5.0; 
float b = 5.0;
a  = a % b;
// not allowed
Run Code Online (Sandbox Code Playgroud)

我试图用这种函数重载运算符%:

template <>
MyClass*                MyClass<float>::operator%(Myclass &other)
Run Code Online (Sandbox Code Playgroud)

对于其他涉及浮动的操作,我使用:

template <class T>
MyClass*                MyClass<T>::operator%(MyClass &other)
Run Code Online (Sandbox Code Playgroud)

它从来没有编译实际上我被卡住了,无法找到绕过这个问题的方法,g ++仍然警告我你不能对浮点数执行模数,我的模板语法有问题或者它真的不可能.

c++ templates g++

3
推荐指数
1
解决办法
4451
查看次数

将vector <wstring>与Boost.Pool分配器一起使用

我尝试使用Boost.Pool分配器vector<wstring>,希望在通常分配某种形式的性能增益vector<wstring>(我期待某种快速的结果像这些).

然而,似乎有了Boost.Pool,我实际上会得到更糟糕的结果,例如:

  • 对于计数为15,000次的迭代,0 ms显示为通常分配vector<wstring>,而使用Boost.Pool的经过时间为5900 ms;

  • 对于5,000,000次迭代的计数,使用默认分配器完成循环需要大约1300 ms,而boost::pool_allocator需要花费大量时间(一分钟后我用Ctrl+ 打破C).

这是我写的C++代码基准:

//////////////////////////////////////////////////////////////////////////
// TestBoostPool.cpp
// Testing vector<wstring> with Boost.Pool
//////////////////////////////////////////////////////////////////////////


#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

// To avoid linking with Boost Thread library
#define BOOST_DISABLE_THREADS

#include <boost/pool/pool_alloc.hpp>
#include <boost/timer/timer.hpp>

using namespace std;

void Test()
{
  // Loop iteration count
  static const int count = 5*1000*1000;

  //
  // …
Run Code Online (Sandbox Code Playgroud)

c++ performance boost

3
推荐指数
1
解决办法
2795
查看次数

功能无法访问

我有

// file BoardInitializer.h
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>

using namespace std;
class BoardInitializer
{
    static int *beginBoard;
    static int *testBoard;
    static void testBoardInitialize();
}



// file mh.cpp
#include "BoardInitializer.h"

int main(int argc, char* argv[])
{
    BoardInitializer.testBoardInitialize();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我实施BoardInitializer::testBoardInitializemh.cpp.但我收到错误"功能无法访问".怎么了?

c++

3
推荐指数
3
解决办法
9572
查看次数

如何检查库是否使用-fno-rtti编译?

假设一个简单的文件bla.cpp:

struct MyClass {
  virtual int foo(int x);
  virtual ~MyClass();
};


int MyClass::foo(int x) { return x + 23; }
MyClass::~MyClass() {}
Run Code Online (Sandbox Code Playgroud)

用它构建一个共享库

g++ -c -fPIC bla.cpp
g++ -shared -o bla.so bla.o
Run Code Online (Sandbox Code Playgroud)

通常会包含一些type_info符号,因为默认情况下在gcc上启用了RTTI.但是,如果我建立

g++ -c -fPIC -fno-rtti bla.cpp
Run Code Online (Sandbox Code Playgroud)

type_info将丢失.

是否有一种简单,可靠的方法(在gcc或上clang)来检查库是否已构建-fno-rtti或使用-frtti?我问,因为今天我盯着臭名昭着的undefined reference to type_info,我花了一点时间才明白,这是因为我正在建立一个与之相关的图书馆-fno-rtti.

c++ linker rtti

3
推荐指数
1
解决办法
1524
查看次数