我在使用常量初始化类时遇到了麻烦:
为什么使用指向同一类中成员的指针初始化会导致错误?出现错误而不使用"使用"类!
class A
{
private:
int a;
const int* const aptr;
public:
constexpr A( int _a):
a(_a)
, aptr( &a) // why aptr could not be initialized?
{}
};
class Data { } d1;
class B
{
private:
Data* dptr1;
public:
constexpr B(Data* _p): dptr1( _p) {}
};
class Use
{
static constexpr A a{2}; // fail! error: field initializer is not constant
static constexpr B b{&d1}; // works
};
Run Code Online (Sandbox Code Playgroud) 我有一个运行3.2内核的powerpc板.使用sysfs访问gpio按预期工作,例如
> echo 242 > /sys/class/gpio/export
> cat /sys/class/gpio/gpio242/value
> 1
Run Code Online (Sandbox Code Playgroud)
是否没有API直接从用户空间访问gpio引脚?我必须处理基于文本的sysfs接口吗?
我搜索的内容如下:gpio_set(int no,int val);
谢谢克劳斯
如果一个类有一个像这样的特殊成员函数(在另一个例子中找到),我尝试专门化一个模板:
template <typename T>
class has_begin
{
typedef char one;
typedef long two;
template <typename C> static one test( decltype( &C::AnyFunc) ) ;
template <typename C> static two test(...);
public:
enum { value = sizeof(test<T>(0)) == sizeof(char) };
enum { Yes = sizeof(has_begin<T>::test<T>(0)) == 1 };
enum { No = !Yes };
};
Run Code Online (Sandbox Code Playgroud)
这很有效,直到AnyFunc重载:
class B : public vector<int>
{
public:
void AnyFunc() const;
void AnyFunc();
};
Run Code Online (Sandbox Code Playgroud)
如何从我的模板中重写我的测试代码以获得"是"?
我想在gtk ++中使用与goocanvas相关的lambda表达式.根据我的理解,这意味着我必须能够将我的lambda放在sigc ++ functor中.
我试过这样的事情:
sigc::slot<bool, const Glib::RefPtr<Goocanvas::Item>& , GdkEventMotion* > slot2=
[]( const Glib::RefPtr<Goocanvas::Item>& item, GdkEventMotion* ev)->bool
{
cout << "Lambda " << endl; return false;
};
((Glib::RefPtr<Goocanvas::Item>&)item1)->signal_motion_notify_event().connect( slot2);
Run Code Online (Sandbox Code Playgroud)
但这不会编译.
有没有机会让sigc直接使用lambdas或更好的gtkmm没有sigc ++中间体:-)
如果我使用:
Gtk::Button* button = Gtk::manage( new Gtk::Button(Gtk::Stock::DELETE));
Run Code Online (Sandbox Code Playgroud)
它工作完美,但文档和标题显示:已弃用,使用标签 _Delete
但如果我简单地写
Gtk::Button* button = Gtk::manage( new Gtk::Button("_Delete"));
Run Code Online (Sandbox Code Playgroud)
该按钮仅显示文本_Delete。
如何以“新”时尚创建标准按钮?
更新:根本没有计划让 gtk 中的任何东西变得自动化。开发者邮件列表上进行了长时间的讨论。他们决定不再更换库存物品。这简单的意思就是:所有的事情自己做!:-(
在创建新的git存储库并将其推送到基于ssh的git服务器时,我很困惑.
我做了什么:
mkdir knowledge_base
cd knowledge_base
git init
Run Code Online (Sandbox Code Playgroud)
(创建一些文件)
git add <some files>
git commit -m 'initial'
Run Code Online (Sandbox Code Playgroud)
直到这里一切都很完美
现在做一个:
git remote add origin ssh://gitzfrdh@ex/home/gitzfrdh/gitrepos/knowledge_base
git push --set-upstream origin master
Run Code Online (Sandbox Code Playgroud)
错误:
致命:'/ home/gitzfrdh/gitrepos/knowledge_base'似乎不是一个致命的git存储库:无法从远程存储库中读取.
请确保您具有正确的访问权限并且存储库存在.
是的,我知道回购不存在.我的想法是推动这个新的.
我必须首先在服务器端创建一个裸仓库吗?
编辑:如果我在服务器上执行:
mkdir knowledge_base
cd knowledge_base/
git init --bare
Run Code Online (Sandbox Code Playgroud)
再次在客户端上:
git push --set-upstream origin master
Run Code Online (Sandbox Code Playgroud)
一切都有效.
但我认为不打算在服务器上完全过剩?我错了?
是否可以使用现有的变量作为与之相关的返回值的目标structured bindings?
auto f()
{
return std::make_tuple(1,2.2);
}
int main()
{
int x;
double z;
[ x, z ] = f(); // Did not work in gcc 7.1
// structured bindings only work with "new" vars?
auto [a, b] = f(); // works fine
}
Run Code Online (Sandbox Code Playgroud) 来自这个问题: 如何构建自定义宏,用作constexpr(如assert)时,其行为会有所不同?
我想知道如果有条件的话为什么可以调用非constexpr函数。
void bla( )
{
std::cout << "bla called!" << std::endl;
}
constexpr bool check(bool condition)
{
//bla(); // can not directly be called -> not constexpr!
condition ? void (0) : bla(); // compiles and runs even if condition is true or false!
// if condition is const, it did not compile because it
// directly force execution of non constexpr function
true ? void(0): bla(); // also that compiles!, ok, directly evaluated
//true ? bla(): void(0); …Run Code Online (Sandbox Code Playgroud) 我想使用std::chrono::duration文字,例如10s表示“10 秒”,如下所示:
std::chrono::duration<uint64_t, std::milli> millisecs = 10s;
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
Run Code Online (Sandbox Code Playgroud)main.cpp:20:17: error: unable to find numeric literal operator 'operator""s' millisecs = 20s; main.cpp:22:17: note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes
我已经添加-fext-numeric-literals到我的 gcc 编译命令中:
std::chrono::duration<uint64_t, std::milli> millisecs = 10s;
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如果我进行部分专业化,我会从 clang 和 g++ 得到不同的结果。
template < typename T>
class X
{
public:
T i;
X(T _i): i{_i}{}
operator T(){ return i; }
};
template < typename T2 >
class Y
{
public:
template <typename T>
static X<T> x_in_y;
};
template< typename T2>
template< typename T>
X<T> Y<T2>::x_in_y{200};
template<>
template<>
X<float> Y<int>::x_in_y<float>{100};
template<>
template<>
X<int> Y<int>::x_in_y<int>{101};
template< >
template< typename T >
X<T> Y<bool>::x_in_y{77};
int main()
{
std::cout << Y<int>::x_in_y<int> << std::endl;
std::cout << Y<int>::x_in_y<float> << std::endl;
std::cout << Y<float>::x_in_y<float> …Run Code Online (Sandbox Code Playgroud) c++ templates template-specialization variable-templates c++14