static_cast without angled brackets code snippet I don't undestand - c++

I am looking at implementing a c++ wrapper for c-based freeRtos. I found this link
Its only a short bit of code, but inside it has the following:
static void taskfun(void* parm) {
static_cast(parm)->task();
:
}
I always thought that static_cast needs <type> after it. Can someone explain what this code is doing for me? - I feel like I am missing somthing fundamental here :o

I feel like I am missing somthing fundamental here :o
You are: the other HTML that was not properly escaped when that post is rendered.
The HTML of that specific post is as follows:
<pre><br> void taskfun(void* parm) {<br> static_cast<classname *>(parm)->memberfun();<br>}<br></pre>
So really the text should be:
void taskfun(void* parm) {
static_cast<classname *>(parm)->memberfun();
}

Related

Bukkit - Referring to a custom item in an IF statement doesn't work

Apologies for terrible use of words but I'm not into the lingo yet.
I've been creating a spell book for a simple bukkit plugin which opens into an inventory on the right click of a certain custom item that is crafted. Here is the code
#EventHandler
public void onBookInteract(PlayerInteractEvent e){
if(e.getAction() == Action.RIGHT_CLICK_AIR){
if(e.getItem() == SpellBook){
openGUI(e.getPlayer());
When I try to do this ingame nothing happens. I've removed if(e.getItem() == SpellBook){ and it works as well as if I change the statement to:
if(e.getMaterial() == Material.BLAZE_POWDER){
It works as well. Probably a simple error but I only started coding a couple of days ago. Thanks for any and all helpful feedback ^_^
There are a couple things that could be wrong.
1) Make sure that the class that this is in implements Listener, and that in your Main class, (the one that extends JavaPlugin) in the onEnable() method, you have:
this.getServer().getPluginManager().registerEvents(new <class that implements Listener>(), this);
so if the class that your code with #EventHandler is in is called Handler, then you would use:
this.getServer().getPluginManager().registerEvents(new Handler(), this);
2) Try using .equals() instead of ==:
if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
if(e.getItem().equals(SpellBook)){
3) Make sure that SpellBook is actually an ItemStack. If it is, then you may want to try doing this if it has no ItemMeta (display name, lore, etc.)
if(e.getItem().getType().equals(SpellBook.getType())){
Otherwise, if it does have ItemMeta, you could use this:
if(e.getItem().getType().equals(SpellBook.getType()) && e.getItem().hasItemMeta()){
if(e.getItem().getItemMeta().getDisplayName().equals(SpellBook.getItemMeta().getDisplayName(){
if(e.getItem().getItemMeta().getLore().equals(SpellBook.getItemMeta().getLore(){
So, your final code should probably look something like this:
#EventHandler
public void onBookInteract(PlayerInteractEvent e){
if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
if(e.getItem().getType().equals(SpellBook.getType()) && e.getItem().hasItemMeta()){
if(e.getItem().getItemMeta().getDisplayName().equals(SpellBook.getItemMeta().getDisplayName()){
if(e.getItem().getItemMeta().getLore().equals(SpellBook.getItemMeta().getLore()){
openGUI(e.getPlayer());
}
}
}
}
}
If SpellBook is a type (i.e. a Java class) then that's your problem, e.getItem() returns an instance of a class. Again, if SpellBook is a type (I can't tell with the brief code you gave), then try using e.getItem() instanceof SpellBook instead. Sorry if I'm way off.

Implementation of active appearance models

I'm having an internship in the field of computer vision, and i am really interested to know some details about the implementation of the Active Appearence Models aam-opencv that exists in the Google Code site.
In fact, i downloaded aam-opencv.tar.gz then built it with cmake and i solved some syntax problems but the only error that i am still having when i try to generate the solution is the following :
This function should return something:
aamImage* delaunay:: warpImageToMeanShape(aamImage*input)
{
}
I wonder if there is something missing in that function, or is it a compiler problem.
Please give me an answer or just guide me to complete the missing part of that function.
I would really appreciate if anyone kindly help me.
Thank you.
I suppose that is not used in code function, so it is not important what it return. Some C++ compilers allow to write such code and give only warning, another treat as errors:
ReturnType f()
{
}
looks like you use not the same compiler as author of source code. So just add something like:
aamImage* delaunay:: warpImageToMeanShape(aamImage*input)
{
return NULL;
}

Cursor placement when calling a method with void parameters

This is a fairly straight forward question but I am unable to find an answer about this specific type of formatting. I'm looking for a way to modify where eclipse places the cursor after using its content assist to complete a method call based on whether or not the method has any parameters.
To illustrate what exactly I'm talking about lets consider a simple c++ class like so:
class Example
{
public:
int voidParams()
{
//do something
return 42;
};
int nonVoidParams(int a)
{
//do something else
return a*a;
};
};
And at some point I created an instance of the class Example ex;
Now within eclipse if I started typing ex.nonV and I told eclipse to auto complete it would enter in ex.nonVoidParams() and after doing this my cursor would be inside the parenthesis like so ex.nonVoidParams(|) where | is my cursor. This makes sense and is useful since I need to give this particular method an argument.
Hopefully none of what I just said is new to anyone and is all pretty straight forward. This is where my question comes in. Having my cursor be placed within the parenthesis of a method call is only useful if that method takes parameters. If I were to type ex.voi and let eclipse auto complete to ex.voidParams() my cursor would be inside the parenthesis like so ex.voidParams(|) where | is my cursor. This isn't very useful since there is nothing for me to enter there.
I would like to know if there is a way to setup eclipse so, given the above examples, if it auto completes a method with void parameters such as ex.voidParams() it places the cursor after the method call like so ex.voidParams()| again where | is my cursor.
I'm not super familiar with customizing eclipse but I feel like there should be a way to do this since if eclipse is auto completing the method call it should know what its parameters are and be able to adjust its formatting from there.
Oh and this will probably be asked at some point, I'm currently using Eclipse CDT version 4.2.0 (Juno service Release 2).
Go to Window->Preferences->C++->Editor->Content Assist->Advanced, pick the "Parsing-based Proposals" instead of "Parsing-based Proposals (Task-Focused)".

refining a mesh in VCG

Has anyone done trimesh refining in the VCG library? I would add that as a tag but I don't have high enough reputation yet. Every time I include any of the refine libraries I get the following errors:
../../../addons/ofxVCGLib/vcglib/vcg/complex/trimesh/refine.h:880:0
../../../addons/ofxVCGLib/vcglib/vcg/complex/trimesh/refine.h:880: error: expected
unqualified-id before numeric constant
which is on this line:
typename TRIMESH_TYPE::FacePointer FF0;
the definition that contains that (excuse the giant c/p) looks like this:
template<class TRIMESH_TYPE, class CenterPoint>
void TriSplit(typename TRIMESH_TYPE::FacePointer f,
typename TRIMESH_TYPE::FacePointer f1,typename TRIMESH_TYPE::FacePointer f2,
typename TRIMESH_TYPE::VertexPointer vB, CenterPoint Center)
{
my vertex, face, & mesh are declared like so:
class innerMeshFace:public Face<myTypes, face::FFAdj, face::Mark, face::VertexRef, face::BitFlags, face::Normal3f, face::InfoOcf> {
};
class myVertex:
public Vertex<myTypes, vertex::Coord3f, vertex::BitFlags, vertex::TexCoord2f, vertex::Normal3f, vertex::Mark, vertex::Color4b, vertex::VFAdj, vertex::InfoOcf>
{}
class myMesh:public tri::TriMesh< vector<myVertex>, vector<innerMeshFace> > { }
so I'm not sure if there's something in there that's I'm misunderstanding. I use the myMesh::FacePointer elsewhere in my code, I think there's something in the template pile that I'm missing. This all works fine (i.e. compiles and does what it's supposed to) until I try to include the refine.h. Any pointers from anyone w/VCG experience would be very much appreciated.
After talking to the creators, it turns out this is a problem in how GCC compiles that particular part of the library. I don't understand the details, but LLVM is fine with it, GCC is not. It works fine on Linux but as I was working with it in XCode I was having problems. It's something they're not going to be updating any time soon, so it looks like for the moment VCG mesh-refining isn't working on GCC 4.2.
I got an example of Refine working (finally!) under MingW GCC-3.4.5 http://pastebin.com/uYnCepEY

omnicppcomplete not supporting all forms of const

I have omnicppcomplete working fine except once in a while it won't complete some of the variables methods/members. I finally got annoyed enough to dig into why and I believe the reason is that omnicppcomplete does support the syntax "Foo const & foo" in function arguments.
For example, if I have a function defined as:
int foo( Bar const & b ){
}
I won't be able to get completion information when I later type "b.". However if I change the signature to:
int foo( const Bar & b ){
}
I will be able to get completion information when I type "b.". It seems to only be in function argument lists because I tried simply defining a variable within the function with the signature "Bar const & bref" and I was able to get completion information for bref.
I would be surprised if this is an actual limitation of omnicppcomplete; anyone have any thoughts on whether or not this is a bug and/or if there is a workaround for it? Changing the coding style does not seem like a reasonable solution.
Seems like a limitation in omnicppcomplete, but I pulled up the vim debugger and found it.
Open up autoload/omni/cpp/utils.vim, go to line 518, should look like this:
for token in tokens
if state==0
if token.value=='>'
let parenGroup = token.group
let state=1
elseif token.kind == 'cppWord'
let szResult = token.value.szResult
let state=2
elseif index(['*', '&'], token.value)<0 "This is line 518
break
endif
And change that line to:
elseif token.value != 'const' && index(['*', '&'], token.value)<0
Or, here's the vim commands to do it =):
/index(\['\*', '&'],<CR>itoken.value != 'const' &&<ESC>:w
I'll try submitting this to the maintainer of omnicppcomplete, but it's kind of hackish, dunno if it'll get in. Might've been able to check if token.kind == 'cppKeyword', but I figured I'd err on the side of changing the least.
Having experienced issues with omnicppcomplete, I searched for an alternative and found clang complete which uses clang's metadata output (that is intended for such purposes). I works extremely well and provided your code compiles, it will understand everything.