小编Jam*_*nco的帖子

使用Mingw文件c ++ locale.h的问题 - 我可以更改代码吗?

我目前正在收到构建错误.这个错误看起来像这样

C:/mingw64/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32/bits/c++locale.h: In function 'int std::__convert_from_v(int* const&, char*, int, const char*, ...)':
C:/mingw64/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32/bits/c++locale.h:74:48: error: expected primary-expression before ',' token
     const int __ret = __builtin_vsnprintf(__out, __size, __fmt, __args);
Run Code Online (Sandbox Code Playgroud)

经过调查,我注意到代码C++Locale.h看起来像这样

// Written by Benjamin Kosnik <bkoz@redhat.com>

#ifndef _GLIBCXX_CXX_LOCALE_H
#define _GLIBCXX_CXX_LOCALE_H 1

#pragma GCC system_header

#include <clocale>

#define _GLIBCXX_NUM_CATEGORIES 0

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  typedef int*          __c_locale;

  // Convert numeric value of type double and long double to string and
  // return length of string.  If vsnprintf is available use …
Run Code Online (Sandbox Code Playgroud)

c++ mingw-w64

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

不能在objectiveC xcode中使用@property

我是目标C的初学者,我正在使用以下代码我正在使用xcode6

// Car.h
#import <Foundation/Foundation.h>

@interface Car : NSObject {
    NSString *simple_name;  //This is private
    @property int mssp;     //Cant use @property Error illegal visibility specification
}

-(void) sayHi:(NSString*)msg ;
@end
Run Code Online (Sandbox Code Playgroud)

有关我为什么会收到此错误的任何建议?

objective-c

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

变体宏

我遇到了涉及可变参数宏的代码,我想知道这意味着什么

#define DECLARE_LEGACY_TYPES(...)  //This all of the macro - I am not holding out on anything
Run Code Online (Sandbox Code Playgroud)

现在有这个类

Header file: .h
    namespace LG_Wrapper
    {
        template <LG_Thread Thread>
        class EffectApplication : public ktApplication
        {
        public:
        static EffectApplication<Thread>& GetInstance();
        protected:
            .....
            .....
            static boost::recursive_mutex mResource;
          }
    }

    DECLARE_LEGACY_TYPES(EffectApplication);  <---- What does this do ?
Run Code Online (Sandbox Code Playgroud)

我想知道宏有什么影响?

更新: 我收到了很多关于此的问题,因为这个问题给人的印象是我没有发布宏的全部内容.宏没有更多内容了.我希望有.这个问题是有关该被关闭.这个宏字面上刚刚结束(...)

 #define DECLARE_LEGACY_TYPES(...)
Run Code Online (Sandbox Code Playgroud)

但是没有.这就是我在这里的原因之一,因为我不知道如何处理这种情况.这个宏有效吗?

更多信息:

这是我在另一个文件中使用的,我在项目设置中使用以下定义

LG_WRAPPER_EXPORTS
LG_THREAD_NAME=GAME
Run Code Online (Sandbox Code Playgroud)

以下是代码

namespace LG_Wrapper
{

enum LG_Thread
{
    GAME,
    OTHER
};


/*
If the library itself is including …
Run Code Online (Sandbox Code Playgroud)

c++ macros

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

为什么当map是const static时,以下内容不起作用

请考虑以下示例:

enum class DOG_TYPE {SHEPHARD, COLLIE,UNKNOWN};

static  const std::map<std::string,DOG_TYPE> dogMap = {
                {"GS",DOG_TYPE::SHEPHARD}
};


DOG_TYPE getDogType(const std::string& dogtype) 
{
    if(dogMap.find(dogtype) != dogMap.end())
    {
        return  dogMap[dogtype];  -->Does not work when std::map is constant
    }
}

int main()
{
DOG_TYPE j = getDogType("GS");
std::cout << int(j);
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,该语句return dogMap[dogtype];返回错误

error: passing 'const std::map<std::__cxx11::basic_string<char>, DOG_TYPE>' as 'this' argument discards qualifiers [-fpermissive]
         return  dogMap[dogtype];
Run Code Online (Sandbox Code Playgroud)

我想知道为什么会发生这种情况以及为什么不能映射const static

c++ c++11

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

Python - 将Getter作为带参数的lambda

作为python的新手我刚刚遇到了property关键字,它基本上可以让你分配getter和setter.我想出了这个简单的例子

class foo:
    def __init__(self,var=2):
        self.var= var

    def setValue(self,var):
        print("Setting value called")
        self._var  = var

    def getValue(self):
        print("getting value")

    var = property(getValue,setValue)
Run Code Online (Sandbox Code Playgroud)

现在在我的django项目中,我遇到了类似的东西(在属性中使用lambda)

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    likes_cheese = models.BooleanField(default=True)
    puppy_name = models.CharField(max_length=20)

User.profile = property(lambda u : UserProfile.objects.get_or_create(user=u)[0])
Run Code Online (Sandbox Code Playgroud)

我不知道你可以在一个属性中使用lambda.现在从我的理解是它设置了profile作为lambda的getter并且getter需要一个参数.这种困惑我.所以我决定尝试自己的例子

class double:
    def setValue(self,var):
        print("Setting value called")
        self._var  = var

    def getValue(self):
        print("getting value")

    #var = property(getValue,setValue)
    var = property(lambda x: print("The value of parameter is" + str(x)))

d =double()
d.var #Call the getter but …
Run Code Online (Sandbox Code Playgroud)

python lambda

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

检查json对象中的路径是否存在?

我目前正在做这样的事情来访问我的 json 对象中的数组

teacher_topical_array = teacher_obj["medication"]["topical"]
Run Code Online (Sandbox Code Playgroud)

但是在此之前,我想确保路径teacher_obj["medication"]["topical"]存在,并且我正在寻找一种更简单的方法来完成此操作。

现在我明白我可以做这样的事情

if "medication" in teacher_obj:
    if "topical" in teacher_obj["medication"]:
             #yes the key exists
Run Code Online (Sandbox Code Playgroud)

我想知道我是否可以以不同的方式完成上述任务。如果我必须检查类似的东西,那可能会更有效

teacher_obj["medication"]["topical"]["anotherkey"]["someOtherKey"]
Run Code Online (Sandbox Code Playgroud)

python json dictionary

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

对象实例是否保留相同的内存地址

假设我有以下代码

  foo* f = new foo();
  std::cout << static_cast<void*>(f); //0xcf1c20
Run Code Online (Sandbox Code Playgroud)

现在在上面的代码f指针指向地址0xcf1c20.这是foo实例的地址.我的问题是假设驻留在地址上的上述实例0xcf1c20没有被删除,实例是否会在整个应用程序的生命周期内始终存在于此内存地址中?或者是否存在同一实例可能放在不同的内存地址上的情况?

c++

0
推荐指数
1
解决办法
283
查看次数

调用模板化基类方法编译失败

我试图通过派生类调用模板化的基类方法.这是我的代码

struct base
{
    template<typename t>
    void baseMethod(t s)
    {
        std::cout << s;
    }
};


struct der : public base
{
};


int main()
{
  der d;
  d.<int>(baseMethod(12));
}
Run Code Online (Sandbox Code Playgroud)

编译失败并说明

main.cpp:在函数'int main()'中:main.cpp:25:5:错误:在'<'标记d之前预期的unqualified-id.(baseMethod(12)); ^ main.cpp:25:6:错误:在'int'd之前预期的primary-expression.(baseMethod(12));

有关如何修复它的任何建议?

c++ templates

0
推荐指数
1
解决办法
46
查看次数

函数构造函数可以包含非此变量吗?

我注意到如果我创造这样的东西

var j = function(){
 this.name = "Joe",
 var no = "23" //--->statement 2
}
Run Code Online (Sandbox Code Playgroud)

我得到错误var no ="23"^^^

SyntaxError: Unexpected token var
    at Object.exports.runInThisContext (vm.js:53:16)
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (module.js:541:32)
    at node.js:328:29
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)    
Run Code Online (Sandbox Code Playgroud)

我理解函数构造函数应该使用带有变量的"this",但我很好奇为什么我在语句2中得到错误

javascript

-1
推荐指数
1
解决办法
33
查看次数

使用静态标签从静态路径加载图像

我无法使用以下语法在我的索引页上加载图像

{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}

    <-!---This is the statement-->
   <-div data-src=  "{% static "bootstrap/images/slider/slider-img1.jpg" %}">
   <-/div>

{% endblock content %}
Run Code Online (Sandbox Code Playgroud)

- (dash)在 div 中添加了一个额外的内容,因为该帖子难以显示。

无论如何,我收到错误

Invalid block tag on line 69: 'static', expected 'endblock'. Did you forget to register or load this tag?
Run Code Online (Sandbox Code Playgroud)

我认为这是一个目录结构。我的目录目前看起来像这样

|_mainApp
|  |_______index.html ------>This is where i am trying to run the statement
|_templates
|  |_______base.html ------->The statement works fine in the base
|_static
   |_bootstrap
|_CenterApp …
Run Code Online (Sandbox Code Playgroud)

tags django block static-content

-1
推荐指数
1
解决办法
1294
查看次数

NSLog指针指向的地址

我想NSLog指向指针的地址.我遇到了这个 但是我仍然遇到错误.这是我的代码

    Teacher* t = [[Teacher alloc]init];
    NSLog(@"t points to the address <%p>" &*t);//Error 
Run Code Online (Sandbox Code Playgroud)

错误是

Invalid operands to binary expression ('NSString *' and 'Teacher')
Run Code Online (Sandbox Code Playgroud)

关于如何打印指针地址的任何建议?

objective-c

-2
推荐指数
1
解决办法
138
查看次数

这句话(line,str)= str.split("\n",1)是什么意思?

我熟悉这个split功能,我会这样使用它:

str = "Line1-abcdef \nLine2-abc \nLine4-abcd"
print str.split( )
Run Code Online (Sandbox Code Playgroud)

以上将返回:

['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
Run Code Online (Sandbox Code Playgroud)

简单易行.但是,我遇到了一段包含此声明的代码:

(line, str) = str.split("\n", 1)
Run Code Online (Sandbox Code Playgroud)

这里有两件事我不明白:

  1. 第二个参数split和它的作用.我看了看这里,它说的是行数.那是什么意思?

  2. split返回一个可迭代的向量.为什么要分配(line, str)(line, str)这里的意思是什么?

python string iterable

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