小编cam*_*ino的帖子

如何使用#if,#else,#endif ...在c宏中

 #include < iostream >  

 #define MY_CHK_DEF(flag) \
 #ifdef (flag) \
    std::cout<<#flag<<std::endl; \
 #else \
    std::cout<<#flag<<" ,flag not define"<<std::endl; \
 #endif 


 int main()
 {
    MY_CHK_DEF(FLAG_1);
    MY_CHK_DEF(FLAG_2);
    MY_CHK_DEF(FLAG_3);
    ...  
 }
Run Code Online (Sandbox Code Playgroud)

编者报告:

main.cpp:3:24:错误:'#'后面没有宏参数

有任何想法吗?

谢谢

c c++ c-preprocessor

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

如何在flutter中将未来的<>分配给小部件?

假设我有一个singleChildScrollView,它的内容是从文件中读取的:

new singleChildScrollView(
        padding: new EdgeInsets.all(8.0),
        child: new Text(
          getTextFromFile(), //<---read from file
          style: new TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 19.0,
          ),
        ));

  Future<String> getFileData(String path) async {
    return await rootBundle.loadString(path);
  }

  Future<String> getTextFromFile() async {
      return getFileData("test.txt");
  }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

参数类型'Future'不能分配给参数类型'String'.

如何解决这个问题?

dart flutter

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

在C++中覆盖虚函数时可以更改返回类型吗?

我遇到了关于覆盖虚函数的问题,实际上,它是关于hessian(一种Web服务协议).

它有一个基类Object和一些派生类:Long,Int,String,...,所有派生类都有一个无虚函数"value"

   class Object  
   {  
     ...    
   };  


   class Long :public Object  
   {  
       ...  
   public:  
       typedef long long  basic_type;  
       basic_type value(){return value_;}  
   private:  
       basic_type value_;  
       ...  
   };  


   class Int :public Object  
   {  
      ...  
   public:  
       typedef int basic_type;  
       basic_type value(){return value_;}  
   private:   
       basic_type value_;  
       ...  
   };  
Run Code Online (Sandbox Code Playgroud)

现在我想添加一个函数,比如toString,它可以将Object转换为字符串:

Object *obj  = ...
cout<<obj->toString();
Run Code Online (Sandbox Code Playgroud)

如果我可以将值函数更改为virtual,我只需要在Object中编写一个toString函数,否则,我需要编写一个虚函数toString,并在所有派生类中重写这个函数.

例如

   class Object  
   {  
       virtual Type value(); // It seemed that I can't write a function like this,because the Type is different for different derived classes  


       std::string toString()  
       { …
Run Code Online (Sandbox Code Playgroud)

c++ virtual overriding function

7
推荐指数
2
解决办法
7385
查看次数

如何从linux中的GUI应用程序中提取文本内容?

我想从GUI应用程序中提取文本内容,这里有两个例子::

例1:

假设我打开了firefox,输入了url:www.google.com

如何使用自己的应用程序从firefox中提取字符串"www.google.com"?

例2:

打开计算器(使用gcalctool),然后输入1 + 1

如何从我自己的程序中提取计算器的字符串"1 + 1"?

简而言之,我想要的是找出是否有办法从GUI应用程序的任何小部件中提取文本内容

谢谢

linux ubuntu user-interface

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

如何在PHP中打印出包含标签的原始字符串?

例如:

$str="<script>alert('hello');</script>";
Run Code Online (Sandbox Code Playgroud)

如果我使用echo将其打印出来,它将在浏览器中弹出一个警告窗口.

<script>alert('hello');</script>在这种情况下,如何打印原始字符串?

php

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

为什么QuantLib会引入Handle类?

我检查这张幻灯片,但仍然没有得到:

1) what problem does Handle sovled?

2) what is the benefit to add the Handle class?
Run Code Online (Sandbox Code Playgroud)

从它的源代码,我无法得到任何线索:

   template <class Type>
    class Handle {
      protected:
        class Link : public Observable, public Observer {
          public:
            explicit Link(const shared_ptr<Type>& h =
                                         shared_ptr<Type>());
            void linkTo(const shared_ptr<Type>&);
            bool empty() const;
            void update() { notifyObservers(); }
          private:
            shared_ptr<Type> h_;
        };
        boost::shared_ptr<Link<Type> > link_;
      public:
        explicit Handle(const shared_ptr<Type>& h =
                                         shared_ptr<Type>());
        const shared_ptr<Type>& operator->() const;
        const shared_ptr<Type>& operator*() const;
        bool empty() const;
        operator boost::shared_ptr<Observable>() …
Run Code Online (Sandbox Code Playgroud)

quantlib

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

xargs中的-L和-n有什么区别

每个xargs --help:

-L,--max-lines = MAX-LINES每个命令行最多使用MAX-LINES个非空白输入行

-n,--max-args = MAX-ARGS每个命令行最多使用MAX-ARGS参数

这很令人困惑。-L和-n之间有什么区别吗?

ls *.h | xargs -L 1 echo 
ls *.h | xargs -n 1 echo 
Run Code Online (Sandbox Code Playgroud)

xargs

6
推荐指数
1
解决办法
1106
查看次数

如何在飞镖中分割飞镖类?

我做了以下测试,但是没有用:

//main.dart
class Test
{
  static const   a = 10;
  final b = 20;
  final c = a+1;

}

//part.dart
part of 'main.dart';
class Test
{
  final d = a +1;   //<---undefined name 'a'
} 
Run Code Online (Sandbox Code Playgroud)

我想将flutter教程中的类拆分为多个文件。例如:_buildSuggestions在单独的文件中,_buildRow在单独的文件中,等等。

更新:

我的解决方案:

之前:

//main.dart
class RandomWordsState extends State<RandomWords> {
{
    final _var1;
    final _var2;
    @override
    Widget build(BuildContext context) {
      ...
      body: _buildList(),
    );

    Widget _buildList() { ... }
    Widget _buildRow() { ... }
}
Run Code Online (Sandbox Code Playgroud)

后:

//main.dart
import 'buildlist.dart';
class RandomWordsState extends State<RandomWords> …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

c ++ 11有像quint8这样的东西吗?

Qt中有一些类型,例如在Qt支持的所有平台上保证为8位的quint8.

我想知道C++ 11是否有这种类型?如果没有,那么替代方案是什么?

谢谢.

c++ qt c++11 qtcore

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

在这种情况下,C++会在编译时进行数组边界检查吗?

受到" 使用编译时HTML解析的C++ HTML模板引擎 "的想法的启发,我试图编写一个示例类来检查字符串中的第一个字符是否是a.

int dummy[0];
class Test
{
public:
    constexpr Test(const char *p):p_(p){}
    constexpr void check()const
    {
        if (p_[0]!='a')
            dummy[1]=0;
    }
    const char *p_;
};


constexpr Test operator"" _test(const char *pszText, size_t)
{
  Test t(pszText);
  t.check();
  return t;
}


int main()
{
    //dummy[1] = 0;
    constexpr Test t = "baa"_test;
}
Run Code Online (Sandbox Code Playgroud)

它运行良好(UCCntu上的GCC7.1).如果第一个char不是a,它将给出编译错误:

main.cpp:29:24: error: array subscript value ‘1’ is outside the bounds
of array ‘dummy’ of type ‘int [0]’
constexpr Test t = "baa"_test;
Run Code Online (Sandbox Code Playgroud)

令我感到困惑的是,如果我将代码更改为: …

c++ arrays indexoutofboundsexception c++11

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