Declaring Objects/Scope

Hi! I'm a beginner at C++ and I've been doing some reading on it, but I don't really understand scope pertaining to objects and a bunch of my errors are scope related. Here's an example...

I was given a header called Robot.h which I used to write a cpp file Robot and I want to create a Robot object in my main class, which is in a different cpp file, main.

So in the Robot file, I wrote:

Robot.cpp

Robot::Robot( double maxSpd ) : elapsed( 0 ), traveled( 0 ), Max_Speed( maxSpd ){}

But, I can't figure out how to create a Robot object in main. So far, I've just done this:

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using std::cout ;
using std::endl ;
using std::cin ;


      int main ()
      {

            //The input value used for controlling the robot
            int i ;

            //Opening text and creation of the Robot object, robot
            cout << "Welcome to robot control!" << endl ;
            Robot robot (5) ;
      }


But that declaration is wrong... I knew that, but I still compiled it, just to see what the error was. The error was
'Robot' was not declared in this scope


I'm pretty sure that Robot.cpp needs to be referenced somewhere in main.cpp, but I don't know how-- would I use a #include for that? I guess what I'm asking is, what's the correct way to instantiate an object in C++ when the object's functions and contructors are in another file?
Last edited on
And what is the problem? Where do you see in this module the declaration of Robot? As for me I do not see in this module the declaration of Robot. And the compiler also does not see it. Mayby it is you who sees the declaration?
Last edited on
try including the header file.

 
#include "robot.h" 
Thanks, busturdust! I feel silly... xD It was a very simple solution! Thanks again.
Topic archived. No new replies allowed.