User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 429,996 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,448 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 232 | Replies: 5
Reply
Join Date: Apr 2008
Location: PLANET EARTH
Posts: 43
Reputation: Dannyo329 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
Dannyo329's Avatar
Dannyo329 Dannyo329 is offline Offline
Light Poster

Problem with linking files

  #1  
Jun 30th, 2008
I 've linked the two files together, main.cpp and myClasses.h, I've declared a variable, but what I'm asking is can you access a variable from myClasses.h?

Here's a example of what I got so far:

//main.cpp
#include "myClasses.h"
#include <iostream>

using namespace std;

int main()
{
   ClassOne myClass_instance;
   s = 5;
   cout << "The number is: " << s;

  //etc....
}

//myClasses.h
// MyClasses.h
#ifndef MYCLASSES_H   // note: these are very important!
#define MYCLASSES_H

class ClassOne
{
    public:
      int s;
      
};

#endif



The error i'm getting is something like : s undeclared.
Thanks for the help.
C programmers will get smashed by C++ programmers.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,784
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 320
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem with linking files

  #2  
Jun 30th, 2008
Some info would be usefu such as:

-What OS are you using?
-What compiler or IDE are you using?
-Are those two files saved in the same project, or directory etc?
-How are you compiling it, through the command line or by hitting the compile run button?

-If it isn't an issue to do with linking maybe your class defo or main declaration is wrong.
-Have you tried working with the whole thing in one file?
Last edited by iamthwee : Jun 30th, 2008 at 6:15 am.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,780
Reputation: niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all 
Rep Power: 11
Solved Threads: 185
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Virtuoso

Re: Problem with linking files

  #3  
Jun 30th, 2008
What iamthwee said is all true, but your problem is here: (in red)

Originally Posted by Dannyo329 View Post
ClassOne myClass_instance;
s = 5;
cout << "The number is: " << s;

I think you mean something like:
ClassOne myClass_instance;
myClass_instance.s = 5;
cout << "The number is: " << myClass_instance.s;
Last edited by niek_e : Jun 30th, 2008 at 6:09 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
Reply With Quote  
Join Date: Mar 2008
Location: India, Kerala
Posts: 36
Reputation: RenjithVR is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
RenjithVR RenjithVR is offline Offline
Light Poster

Re: Problem with linking files

  #4  
Jun 30th, 2008
you can use like Object . Variable name;
Last edited by RenjithVR : Jun 30th, 2008 at 8:35 am.
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,780
Reputation: niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all 
Rep Power: 11
Solved Threads: 185
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Virtuoso

Re: Problem with linking files

  #5  
Jun 30th, 2008
Originally Posted by RenjithVR View Post
you can use like Object . Variable name;

How is that different from what I said?
Last edited by niek_e : Jun 30th, 2008 at 10:07 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
Reply With Quote  
Join Date: Apr 2008
Location: PLANET EARTH
Posts: 43
Reputation: Dannyo329 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
Dannyo329's Avatar
Dannyo329 Dannyo329 is offline Offline
Light Poster

Re: Problem with linking files

  #6  
Jul 2nd, 2008
Thanx for the Help. Your suggestion solved the errors!
C programmers will get smashed by C++ programmers.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC