declaration

What type is int(int)& or int(int) const &?

自闭症网瘾萝莉.ら 提交于 2019-12-03 14:08:59
std::is_function is specialized for types which have signature similar to: int(int) & see here: std::is_function But this is neither a pointer to a member method, which signature could be: int(T::*)(int) & Nor it can be a reference to a function: int (&)(int) So what is this strange signature? It's a function type which only exists in the type system. It cannot ever be created. But this is neither a pointer to a member method, which signature could be: int(T::*)(int) & It's this, without the pointer. The type system allows you to describe that as a type. #include <type_traits> struct T { };

Equivalent C declarations

雨燕双飞 提交于 2019-12-03 13:56:50
问题 Are int (*x)[10]; and int x[10]; equivalent? According to the "Clockwise Spiral" rule, they parse to different C declarations. For the click-weary: The ``Clockwise/Spiral Rule'' By David Anderson There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration! There are three simple steps to follow: 1. Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them

Encoding in XML declaration python

六月ゝ 毕业季﹏ 提交于 2019-12-03 13:08:13
I have created an XML file using python. But the XML declaration has only version info. How can I include encoding with XML declaration like: <?xml version="1.0" encoding="UTF-8"?> >>> from xml.dom.minidom import Document >>> a=Document() >>> a.toprettyxml(encoding="utf-8") '<?xml version="1.0" encoding="utf-8"?>\n' or >>> a.toxml(encoding="utf-8") '<?xml version="1.0" encoding="utf-8"?>' you can set the encoding for the document.writexml() function in the same way. 来源: https://stackoverflow.com/questions/2597622/encoding-in-xml-declaration-python

ANSI-C grammar - array declarations like [*] et alii

故事扮演 提交于 2019-12-03 11:53:32
The ANSI C grammar from -link- give me the following rules for array declarations: (1) | direct_declarator '[' type_qualifier_list assignment_expression ']' (2) | direct_declarator '[' type_qualifier_list ']' (3) | direct_declarator '[' assignment_expression ']' (4) | direct_declarator '[' STATIC type_qualifier_list assignment_expression ']' (5) | direct_declarator '[' type_qualifier_list STATIC assignment_expression ']' (6) | direct_declarator '[' type_qualifier_list '*' ']' (7) | direct_declarator '[' '*' ']' (8) | direct_declarator '[' ']' Now I have a some questions about these: Can I use

Why are function declaration mandatory in C++ and not in C?

隐身守侯 提交于 2019-12-03 11:49:18
问题 So one of my previous exams had this question, and till now I've been reading that you don't need a declaration in any of the languages? Which is right? Will C++ give an error if there's no declaration, or will it run? 回答1: In a discussion that involves both C and C++ "function declaration" is a rather vague term. These languages are significantly different in this regard. In C++ language there's only one kind of function declaration: declaration with all parameter types and return type. Such

function vs variable declaration in C++

有些话、适合烂在心里 提交于 2019-12-03 11:03:59
This code works: std::ifstream f(mapFilename.c_str()); std::string s = std::string(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); ParseGameState(s); Whereby mapFilename is an std::string and void ParseGameState(const std::string&); . And this does not: std::ifstream f(mapFilename.c_str()); std::string s(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); ParseGameState(s); This is the error: game.cpp: In member function ‘int Game::LoadMapFromFile(const std::string&)’: game.cpp:423: error: no matching function for call to ‘ParseGameState(std::string (&)

C++: Why must private functions be declared?

∥☆過路亽.° 提交于 2019-12-03 09:27:34
Why do classes in C++ have to declare their private functions? Has it actual technical reasons (what is its role at compile time) or is it simply for consistency's sake? I asked why private functions had to be declared at all, as they don't add anything (neither object size nor vtable entry) for other translation units to know If you think about it, this is similar to declaring some functions static in a file. It's not visible from the outside, but it is important for the compiler itself. The compiler wants to know the signature of the function before it can use it. That's why you declare

Objective-c basics: Object declared in MyAppDelegate not accessible in another class

随声附和 提交于 2019-12-03 09:14:57
I have an object declared in my app delegate: @interface MyAppDelegate : NSObject <UIApplicationDelegate> { ClassName *className; } In another class, I include the app delegate: #import "MyAppDelegate.h" @implementation AnotherClass -(void)doMethod { [className doClassNameMethod]; } This fails at compile time due to className being undeclared. Shouldn't it be accessible, since I've included the MyAppDelegate, where className is declared? I need AnotherClass.doMethod to be accessing the same instance that is created in MyAppDelegate. Any help on this would be most appreciated. Thanks. To access

namespaces, classes and free functions - when do you need fully qualified names

你说的曾经没有我的故事 提交于 2019-12-03 07:44:19
问题 In my example below, why do I have to fully qualify the name of the free function in the cpp to avoid linker errors and why does it work for the class function without? Can you explain the difference? ctest.h: namespace Test { int FreeFunction(); class CTest { public: CTest(); ~CTest(); }; } ctest.cpp: #include "ctest.h" using namespace Test; // int FreeFunction() -> undefined reference error int Test::FreeFunction() -> works just fine { return 0; } CTest::CTest() -> no need to fully qualify

Declaration and prototype difference

二次信任 提交于 2019-12-03 06:38:01
What is the difference between declaration and prototype in C? In which situations they are called declarations and in which prototypes? TL;DR; All prototypes are declarations, but not all declarations are prototypes. Declaration is the generic terminology used in the standards, prototype is more specific. Quoting C11 , chapter §6.7 A declaration specifies the interpretation and attributes of a set of identifiers. [...] and from §6.7.6, Each declarator declares one identifier, and asserts that when an operand of the same form as the declarator appears in an expression, it designates a function