I keep on getting error while trying to add joystick in OI file

With the new vs code, I have been trying to basically copy the code from last year to test it out. However, whenever I try to add a joystick I get an error saying that Joystick does not name a type.

I use c++ command based format.

Here is the code in OI.h

#pragma once
#include “WPILib.h”

class OI {
public:
OI();
Joystick* xbox;
Joystick* atk3;
};

Code in OI.cpp

xbox = new Joystick(0);
atk3 = new Joystick(1);

We used this exact code in many of our robots and worked completely fine. So maybe they have a different way of initializing and referring to the joystick? I know that new phoenix include made constructing Talon SRX different from last year’s code…

Also, I have tried including “Joystick.h” but that didn’t help either…

One of the changes for C++ in 2019 was the removal of the “shim” that put all of the FRC classes in the global namespace in addition to the frc namespace. You need to replace Joystick in your code with frc::Joystick, and similarly for other WPILib classes.

Gah, that’s annoying to do. Do you know if “using namespace” works with frc programming?

It certainly does. You can add using namespace frc; to your code if you wish.

Part of the reason for the change, however, was to avoid accidental naming conflicts between your classes and the WPILib classes, which can result in hard-to-debug problems, so we recommend you don’t do this (similar to how it’s considered bad practice to use using namespace std;), but it does work.

well I got it working for now with frc::“whatever”. I really appreciate your help :slight_smile: