Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: How to make objects accessible from inside classes?

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Posts
    123

    Question How to make objects accessible from inside classes?

    I am writing test software that runs keyboard firmware on a PC (because developing on a PC is faster without uploading to Teensy).
    This code emulates Arduino's Keyboard.print() on a PC and uses it to test class KE:
    Code:
    #include <iostream>
    using namespace std;
    
    class usb_keyboard_class // this emulates Arduino class of same name, but in runs on a PC
    {
    	public:
    		void print(char const * const str) { cout << str; }
    };
    
    usb_keyboard_class Keyboard;
    
    class KE // this is the class being tested, it calls the emulated Keyboard.print()
    {
    	public:
    		void print(char const * const str)
    		{
    			Keyboard.print(char); //compile error: 'Keyboard' was not declared in this scope
    		}
    			
    };
    
    KE ke;
    
    int main()
    {
    	ke.print("print_cpp");
    }
    But g++ gives this compile error:
    'Keyboard' was not declared in this scope

    The test Keyboard object needs to be made accessible from inside other classes. How is that done?
    How does Arduino make it's Keyboard object accessible from inside other classes?
    Arduino defines and instantiates Keyboard in arduino-1.0.5\hardware\teensy\cores\usb_hid\usb_api.cpp
    Code:
    // Preinstantiate Objects //////////////////////////////////////////////////////
    	usb_keyboard_class	Keyboard = usb_keyboard_class();
    Thank you for reading this long post.
    Last edited by wolfv; 12-25-2013 at 04:58 PM.

  2. #2
    Senior Member
    Join Date
    Jul 2013
    Posts
    123

    Solved

    I fixed it. Changed typo in class KE
    Code:
    Keyboard.print(char)
    to
    Code:
    Keyboard.print(str);
    and it works fine.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •