declaration

C++ - Function declarations inside function scopes?

痞子三分冷 提交于 2019-12-22 05:34:08
问题 I was going through C++11 standard draft a while ago and came across this one (in §8.3.6, p. 204): void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow // a parameter with a default argument void f(int, int); void f(int, int = 7); void h() { f(3); // OK, calls f(3, 7) void f(int = 1, int); // error: does not use default // from surrounding scope } void m() { void f(int, int); // has no defaults f(4); // error: wrong number of arguments void f(int, int = 5); // OK f(4); //

Does T D[N] always declare an object of array type?

南笙酒味 提交于 2019-12-22 05:10:30
问题 I'm confused about [dcl.array]/1: In a declaration T D where D has the form D1 [ constant-expression opt ] attribute-specifier-seq opt and the type of the identifier in the declaration T D1 is “ derived-declarator-type-list T”, then the type of the identifier of D is an array type; ... Consider the declaration: int (*p)[42]; This declaration satisfies the grammar described above (and does not satisfy the grammar described in previous paragraphs), so this paragraph should apply, thus we

error: expected declaration specifiers or ‘…’ before ‘list_node’

点点圈 提交于 2019-12-21 12:12:04
问题 I have a catalog.h file with this typedef struct node* list_node; struct node { operationdesc op_ptr; list_node next; }; and a parser.h with this #include "catalog.h" int parse_query(char *input, list_node operation_list); Both headers have #ifndef , #define , #endif . The compiler gives me this error: expected declaration specifiers or ‘...’ before ‘list_node’ on the parse_query line. What's the matter? I tried to put the typedef in parser.h, and it's fine. Why do I get this error when the

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

爷,独闯天下 提交于 2019-12-21 04:00:34
问题 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

TS4023: Exported Variable <x> has or is using name <y> from external module but cannot be named

眉间皱痕 提交于 2019-12-21 03:37:33
问题 I've seen this answered before, but they don't seem to cover this specific use case (or they don't work/help) import {Route} from 'vue-router'; export const detailRoute = { path: '/detail/:id', component: Detail, props: (route: Route) => ({ state: route.query.state }) }; detailRoute uses Route, which I am importing, but I guess as a named import {Route} it doesn't work? Is there a different/better way to do this that will work? I tried export {Route}; as well, but that didn't help. tsconfig

C++: Why must private functions be declared?

☆樱花仙子☆ 提交于 2019-12-21 03:24:10
问题 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? 回答1: 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

Declaration and prototype difference

試著忘記壹切 提交于 2019-12-20 20:16:56
问题 What is the difference between declaration and prototype in C? In which situations they are called declarations and in which prototypes? 回答1: 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

Declare an array of objects using a for loop c++

强颜欢笑 提交于 2019-12-20 15:33:11
问题 Okay. So I have declared an array of objects, and I have manually defined them using this code: Object* objects[] = { new Object(/*constructor parameters*/), new Object(/*constructor parameters*/) }; Is there anyway to use some kind of a loop (preferably a for loop) to declare these? Something like: Object* objects[] = { for(int i=0; i<20; /*number of objects*/ i++) { new Object(/*constructor parameters*/); } }; But with proper syntax? 回答1: I strongly suggest using a standard library

Comma omitted in variadic function declaration in C++

青春壹個敷衍的年華 提交于 2019-12-20 10:58:40
问题 I am used to declaring variadic functions like this: int f(int n, ...); When reading The C++ Programming Language I found that the declarations in the book omit the comma: int f(int n...); // the comma has been omitted It seems like this syntax is C++ specific as I get this error when I try to compile it using a C compiler: test.c:1:12: error: expected ‘;’, ‘,’ or ‘)’ before ‘...’ token int f(int n...); Is there any difference between writing int f(int n, ...) and int f(int n... )? Why was

Forward declare typedef within C++ class

血红的双手。 提交于 2019-12-20 10:46:37
问题 What's the best solution to forward declare a typedef within a class. Here's an example of what I need to solve: class A; class B; class A { typedef boost::shared_ptr<A> Ptr; B::Ptr foo(); }; class B { typedef boost::shared_ptr<B> Ptr; A::Ptr bar(); }; I suppose I could just do the following: boost::shared_ptr<B> foo(); But is there a more elegant solution? 回答1: There is no such thing as forward declaring a typedef unfortunately. However, there's a trick using late template instantiation: