|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Declaring DoubleSolonoid
Try:
DoubleSolenoid grabSolenoid = new DoubleSolenoid(1, 1, 1); |
|
#2
|
|||
|
|||
|
Re: Declaring DoubleSolonoid
Could not convert '(operator new(104u), (<statement>, ((DoubleSolenoid*) <anonymous>)))' from' 'DoubleSolenoid*' to 'DoubleSolenoid'
|
|
#3
|
|||||
|
|||||
|
Re: Declaring DoubleSolonoid
Oh, yeah, C++ forum...try:
DoubleSolenoid *grabSolenoid = new DoubleSolenoid(1, 1, 1); |
|
#4
|
||||
|
||||
|
Re: Declaring DoubleSolonoid
Oops, my bad... The syntax is almost identical between java and c++, expert for that annoying *. I really hate dealing with punters in c++!
They issue you were having was that you hadn't declared your variable before assuming it, so the compiler didn't know what "grabSolenoid" was. By adding the class in front, you're telling the compiler what that is. |
|
#5
|
|||
|
|||
|
Re: Declaring DoubleSolonoid
Here is a bit of explenation.
Could not convert '(operator new(104u), (<statement>, ((DoubleSolenoid*) <anonymous>)))' from' 'DoubleSolenoid*' to 'DoubleSolenoid' The bolded parts are the important notes. Note the asterisk (or 'star') in the from and also note that it is missing in the to. The new operator creates a new version of the class (DoubleSolenoid here) and returns a pointer to it. The asterisk (or 'star') indicates changes the type of grabSolenoid to a "pointer to DoubleSolenoid", thus making the types on both sides the same. Pointers are one of the more confusing aspects of C/C++, however they are used everywhere. Remember, the pointer doesn't hold the data, it just points to where it is at. For classes, use the -> operator to access methods and fields from the pointer. |
|
#6
|
|||
|
|||
|
Re: Declaring DoubleSolonoid
Thanks, they do declare now, however...
Quote:
I really don't understand these pointers, when I try to set the solenoids using something like grabSolenoid.set(DoubleSolenoid::kForward); it says "request for member 'set' in '(((Robot*)this))->Robot::grabSolenoid', which is of pointer type 'DoubleSolenoid' (maybe you meant to use '->' ?)" where do I put the ->? |
|
#7
|
|||
|
|||
|
Re: Declaring DoubleSolonoid
Try grabSolenoid->Set(DoubleSolenoid::kForward);
|
|
#8
|
|||||
|
|||||
|
Re: Declaring DoubleSolonoid
Quote:
Just replace the '.' with '->' between the variable name and the function name. |
|
#9
|
|||||
|
|||||
|
Re: Declaring DoubleSolonoid
Yes. obj_ptr->elt is equivalent to (*obj_ptr).elt . That is, look up the actual field or method within the object that obj_ptr points to.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|