•
•
•
•
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
![]() |
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:
The error i'm getting is something like : s undeclared.
Thanks for the help.
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.
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?
-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.
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,780
Reputation:
Rep Power: 11
Solved Threads: 185
What iamthwee said is all true, but your problem is here: (in red)
I think you mean something like:
•
•
•
•
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
do NOT pm me for help, in the best case, you'll get ignored
•
•
Join Date: Mar 2008
Location: India, Kerala
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 6
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,780
Reputation:
Rep Power: 11
Solved Threads: 185
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
do NOT pm me for help, in the best case, you'll get ignored
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- problem linking my files (C++)
- Problems Linking C++ Files (C++)
- Dreamweaver Problem with linking files! (HTML and CSS)
- Linking files for Compilation in C++ Data Structures (C++)
- problems wid cpp files (C++)
Other Threads in the C++ Forum
- Previous Thread: proplem with virtual functions and vectors
- Next Thread: Wrtting into multiple files using loop



Linear Mode