declaration

Can we have absolute namespace in function definition if return type is an object in C++?

点点圈 提交于 2019-12-01 09:28:59
问题 Let us consider a function bar declared in namespace foo which returns a std::vector< float > (but also works with other objects). // header.h #include <vector> namespace foo { ::std::vector< float > bar(); } Compiling its definition using relative namespace works. #include "header.h" ::std::vector< float > foo::bar() { } However, compiling its definition using absolute namespace does not work. #include "header.h" ::std::vector< float > ::foo::bar() { } Return error from GCC is function.cpp:3

Java generic method declaration fundamentals

一笑奈何 提交于 2019-12-01 09:09:37
问题 I'm starting to learn Generics for Java and I read several tutorials, but I'm a bit confused and not sure how a generic method is declared. When I use a generic type, what is the correct order to define the method? I found this sample, when do I need to use the angle brackets and when not? public class Box<A> { private A a; ... public void setA(A a) { this.a = a; } public <A> List<A> transform(List<A> in) { return null; } public static <A> A getFirstElement(List<A> list) { return null; }

use of @property and @synthesise?

懵懂的女人 提交于 2019-12-01 08:40:38
I was wondering what the point of @property and @synthesise were. At the moment I use the following to declare something: //Class.m #import "Class.h" CCNode *node; @implementation //init, etc.. But I have seen others use: @property (nonatomic, etc..) CCNode* node; @synthesise (nonatomic, etc..) node; //I am not too sure on how this type of declaration works, please correct me on how it's done. They both seem to work in the same way, what are the advantages of the @property and @synthesise way? Do they do different things, if so, what? @property and @synthesize are two objective C keyword that

Why does this use of comma work in a expression but fail in a declaration?

纵饮孤独 提交于 2019-12-01 06:19:40
Am from high level OOP languages C# and Java and recently started scratching my head in C. I feel C a bit weird as equally as one feels JS is. So want to clarify below: Below gives error and that seems intuitive as it looks like incorrect syntax even in OOP languages int i=0,1,2; /* Error : expected identifier or ‘(’ before numeric constant int i = 0, 1, 2; ^ */ However below works surprisingly: int i; i = 0,1,2; //works Why is this behavior? Is their any significance to keep such behavior or just some parsing technicalities? This is actually a tricky question because it relies on the details

“variable declared and not used” compilation error

♀尐吖头ヾ 提交于 2019-12-01 04:34:27
I am learning Google's new language Go . I am just trying stuff out and I noticed that if you declare a variable and do not do anything with it the go compiler ( 8g in my case) fails to compile with this error: hello.go:9: error declared and not used . I was suprised at this since most language compilers just warn you about unused variables but still compile. Is there anyway I can get around this? I checked the documentation for the compiler and I don't see anything that would change this behaviour. Is there a way to just delete error so that this will compile? package main import "fmt" import

conditional component declaration and a following if equation

点点圈 提交于 2019-12-01 04:25:55
I am trying to build a model that will have slightly different equations based on whether or not certain components exist (in my case, fluid ports). A code like the following will not work: parameter Boolean use_component=false; Component component if use_component; equation if use_component then component.x = 0; end if; How can I work around this? If you want to use condition components, there are some restrictions you need to be aware of. Section 4.4.5 of the Modelica 3.3 specification sums it up nicely. It says "If the condition is false, the component, its modifiers, and any connect

Should a const static variable be initialized in a c++ header file?

扶醉桌前 提交于 2019-12-01 04:20:25
my_test.h #ifndef MY_TEST #define MY_TEST struct obj { int x; int y; }; class A { private: const static int a=100; const static obj b; }; const obj A::b={1,2}; #endif When compiling cpp using this header file, an error 'multiple definition of 'A::b' occurs. why is this when I have been using guard macro already? why does A::a not produce the erro? (I can't write code const static obj b={1,2} in class A ) Alok Save why is this when I have been using guard macro already? Header guards only prevent the inclusion of the header file contents more than once in the same translation unit not across

abstract class declarations in c++

99封情书 提交于 2019-12-01 04:11:46
Suppose foo is an abstract class in a C++ program, why is it acceptable to declare variables of type foo* , but not of type foo ? Because if you declare a foo you must initialize/instantiate it. If you declare a *foo, you can use it to point to instances of classes that inherit from foo but are not abstract (and thus can be instantiated) You can not instantiate an abstract class. And there are differences among following declarations. // declares only a pointer, but do not instantiate. // So this is valid AbstractClass *foo; // This actually instantiate the object, so not valid AbstractClass

Understanding Const expression in VBScript

百般思念 提交于 2019-12-01 04:02:42
Well, I try to understand limitations in Const expressions in VBScript . I was not able to use anything except literals. What the docs say is: Literal or other constant, or any combination that includes all arithmetic or logical operators except Is . So, if "that includes all arithmetic or logical operators" then logically I expect I can do something like this: Const X = (1 + 2) But that brings the error "Expected literal constant". I found an interesting answer here that allows one to cheat, at some level, so the above can be done with: Execute "Const X = " & (1 + 2) But my question is about

Create an instance of a class in the class itself [duplicate]

女生的网名这么多〃 提交于 2019-12-01 03:32:36
This question already has an answer here: Can a c++ class include itself as an member? 4 answers I am new to C++ and have a question: Compare following code: class Node { public: int data; Node* x; }; and class Node { public: int data; Node x; }; I know the second part of code can't pass compile. But I want to know the reason. Is it related to memory allocation or just syntax regulation? I would be appreciate if someone can solve my question. The code in your second fragment cannot compile, because the class Node is not completely defined at the point where you declare its data member x of