Go to Post And like Woodie told us in his talk, all the bad stuff we anguished over will be replaced by the memories of the achievements and good time we had this year. - Wayne C. [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-28-2009, 11:36 AM
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
define a new class(C++)

hello, i'v been trying to define a new class of my own in c++
and i dont know why but the Windriver isnt recognizing my class..

where i need to put the H and the Cpp files?

do i need to define the class in the Windriver somehow?


tnanks alot
Reply With Quote
  #2   Spotlight this post!  
Unread 01-28-2009, 03:37 PM
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
hello, i'v been trying to define a new class of my own in c++ and i dont know why but the Windriver isnt recognizing my class..
where i need to put the H and the Cpp files?
do i need to define the class in the Windriver somehow?
tnanks alot
Please elaborate on what you mean when you say Windriver isn't recognizing your class.
Have you created a downloadable kernel module project?
If so, have added the .h and .cpp file(s) to that project?
If so, have you built the containing project?
You haven't given enough information about what you've tried and how you went about things.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-28-2009, 05:44 PM
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

My code is working , i dont have any problems while downloading the code to
the robot ,

When you say to add the H and Cpp files , you mean copy them to the directory? or that i need to make another proccess in the WindRiver to add them?

and yes , i can build my project , the Windriver isnt recognize the class
unlike the Jaguar or the PWM classes for example...

hope you understand... thanks anyway..
Reply With Quote
  #4   Spotlight this post!  
Unread 01-28-2009, 05:57 PM
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
add the H and Cpp files , you mean copy them to the directory?
OK, what you need to do is drag the files from a Windows explorer window and drop them right onto the project in the Workbench Project Navigator view.
They will then become part of your project and will be compiled and linked with it.
Make sure to drop the files on the top of the project -- not somewhere in the middle. The best thing to do is collapse the project so you can't see any of what's inside. That way, you can't miss with dragging and dropping.

Here's a snippet from the Eclipse documentation (which should be avaliable to you by using Help->Help Contents in Workbench)

Importing files

Files can be imported into the Workbench either by :

* dragging and dropping from the file system, or
* copying and pasting from the file system, or
* Using the Import wizard.

Using drag and drop or copy/paste to import files relies on operating system support that is not necessarily available on all platforms. If the platform you are using does not have this support, you can always use the Import wizard.

Last edited by gvarndell : 01-28-2009 at 06:29 PM. Reason: extra info
Reply With Quote
  #5   Spotlight this post!  
Unread 01-28-2009, 06:02 PM
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: define a new class(C++)

Your question is still a little confusing. Do you see the files that you created in the tree on the left? If not, follow the instructions below.

If you're creating files from scratch, right click on the project and go to add new file (don't remember the exact command). This will add an empty file to your project directory.

If you already created the files, you can copy them into your project directory just like you would any other file (via Windows Explorer, shell, etc). You will then need to right click on the project and go to refresh in order for the files to show up in the tree.

If the files are in the source tree, does the compiler attempt to build them? If you intentionally add a syntax error does the compiler catch it? If not, check the build target in the tree (I think it's green) and check to see if it is picking up all files in your project.

Are you adding a #include or forward declaration in the files that use the classes?

If there are compiler errors that you are getting, it would be helpful for you to post them here. That way people will be able to help you pinpoint your problem.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-29-2009, 09:33 AM
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

I tried to drugg the files to the project and right , my class suddenly is being recognize by the code, but now the class i'v belt is not recognize the other classes like PWM or DigitalInput and so on (thats the errors that i get)
Reply With Quote
  #7   Spotlight this post!  
Unread 01-29-2009, 09:49 AM
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
I tried to drugg the files to the project and right , my class suddenly is being recognize by the code, but now the class i'v belt is not recognize the other classes like PWM or DigitalInput and so on (thats the errors that i get)
You have transitioned from Workbench problem to basic C++ programming problem. I'll have to let others help you with that but I would suggest providing more information than you have. People tend to not help when it's too much work.
Reply With Quote
  #8   Spotlight this post!  
Unread 01-29-2009, 02:40 PM
Pancake Pancake is offline
Registered User
FRC #0991 (The Dukes)
Team Role: Photography
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Phoenix
Posts: 11
Pancake is an unknown quantity at this point
Re: define a new class(C++)

Typically, there's two files, the header file and the CPP file.

Example Header
Code:
// Camera.h
#ifndef CAMERA_H
#define CAMERA_H

class Camera
{
public:
    void doSometing();
};

#endif
Then make a .cpp file with the same name as the header file:
Code:
// Camera.cpp

#include "Camera.h"

void Camera::doSomething()
{
    printf("Doing something...");
}
Now when you get to the robot code, all you need to do is simply include the "Camera.h" file:

Code:
//MyRobot.cpp
#include "Camera.h"

class MyRobot : public SimpleRobot
{
    /* Code ommited for simplicity */
    void Autonomous()
    {
        Camera c();
        c.doSomething();
    }
};

START_ROBOT_CLASS(MyRobot);
Hope this example helps...
__________________
Team Webmaster
Reply With Quote
  #9   Spotlight this post!  
Unread 01-29-2009, 04:01 PM
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
Re: define a new class(C++)

Make sure that you put in the proper include files at the top of your class source files. For example, look your example robot code as provided by WPI and look at the top of the file. There are #include files there. Make sure that you have enough includes to recognize the wpi library. The simplest is to #include "WPILib.h"
Reply With Quote
  #10   Spotlight this post!  
Unread 01-29-2009, 05:46 PM
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

i didnt put those lines

#ifndef CAMERA_H
#define CAMERA_H

and the #endif..

what is this macro? or its not macro?

and why in the OperatorControl you access you class by typing
Camera c();

and not
Camera *c;
c = new Camera();

?
Reply With Quote
  #11   Spotlight this post!  
Unread 01-29-2009, 06:08 PM
wt200999's Avatar
wt200999 wt200999 is offline
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 321
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: define a new class(C++)

http://www.cplusplus.com/doc/tutorial/

(or any other C++ tutorial/book)
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #12   Spotlight this post!  
Unread 01-29-2009, 06:14 PM
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
i didnt put those lines

#ifndef CAMERA_H
#define CAMERA_H

and the #endif..

what is this macro? or its not macro?
It's called a header guard. You can read about it here or here

Quote:
why in the OperatorControl you access you class by typing
Camera c();

and not
Camera *c;
c = new Camera();
In the end both of those do the same thing, instantiate a Camera called c. Which one you use depends on how you plan to use it. If you're only using it in that location and you don't need to pass it around, you can use the non-pointer version. If you plan to be passing the object around, or it is an attribute of a class you'll want to use the pointer approach.

Last edited by Dave Scheck : 01-29-2009 at 06:16 PM.
Reply With Quote
  #13   Spotlight this post!  
Unread 11-01-2010, 11:05 PM
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Re: define a new class(C++)

I'm having a similar problem as described above. I'm trying to get the Logitech Gamepad to work with our robot. I've found the .h and .cpp files I need. I've included the .h file in the WPILib and included the reference (#include) at the top of my source program. Do I need to do something with the .cpp file? If so, what?

Windriver will build my project just fine and download it to the robot. The problem is that the robot doesn't recognize the code. It acts like there isn't anything there. The only thing I can think of is that I must be doing something wrong with the gamepad files. Please help!

Thanks,
Eric
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
define irswitch? Lilor Programming 3 02-10-2008 07:21 PM
Define Happiness Elgin Clock Chit-Chat 17 04-30-2007 09:59 PM
Define A Wedge T3_1565 Rules/Strategy 18 01-11-2007 09:22 PM
Define FIRST slickguy2007 General Forum 24 10-13-2006 08:24 AM
**FIRST EMAIL**/FIRST Announces New Class of Senior Mentors. Billfred FIRST E-Mail Blast Archive 1 12-23-2004 01:32 PM


All times are GMT -5. The time now is 09:31 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi