Jump to content
  • Advertisement
Sign in to follow this  
mudd1038

C++ passing classes into functions

This topic is 2995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, i'm new at this, and i have the following problem:

i'm attempting to pass an object of class CHEMICAL into class SOLVER, and i have the following files:

main.cpp
CHEMICAL.h (defines class CHEMICAL)
SOLVER.h (defines class SOLVER)
deriv.cpp (a function in class SOLVER)

when i paste these files into main.cpp in the order above instead of including them, the program builds fine, but in separate files as such i get build errors:

error C2061: syntax error : identifier 'CHEMICAL'

main.cpp #includes CHEMICAL.h and SOLVER.h, and deriv.cpp #includes its parent SOLVER.h.

any ideas? thanks SO much for any advice.

Share this post


Link to post
Share on other sites
Advertisement
Are your .h in the right folders? You might have to have a link to the folder that you was working in so that your compiler will use your new .h files in your main program.

Share this post


Link to post
Share on other sites
no, folders are fine, thanks though... they're all in the same folder and before i tried to pass a class object those files were all functioning and interacting well.

reading posted article again, no luck yet.

Share this post


Link to post
Share on other sites
You probably need to add
#include CHEMICAL.h
to deriv.cpp.

CHEMICAL.h should be included in the file containing the method definition, so in SOLVER.h.

Share this post


Link to post
Share on other sites
Orione, thanks but no luck there.

here's what i have:

main.cpp:
#include "CHEMICAL.h"
#include "SOLVER.h"
#include "REACTOR.h"

in CHEMICAL.h:
no #includes

in SOLVER.h:
#include "CHEMICAL.h"

in REACTOR.h:
no #includes (just 5 unrelated variables and a function that takes one double)

in deriv.cpp:
#include "SOLVER.h"
#include "CHEMICAL.h" (have tried without this inclusion as well, no luck)





Share this post


Link to post
Share on other sites
thanks so much for all the advice, will look at includeguards next, i'd never heard of that.

i wrote a bare-bones version and got it to build(!) and it seems i run into trouble with a couple things. it fails to build when i include this: (which used to work)

CHEMICAL ();
~CHEMICAL ();

};

CHEMICAL::CHEMICAL () {}

CHEMICAL::~CHEMICAL () {}



and it fails to build when i include this private function:


void copyx(CHEMICAL& x, CHEMICAL &destination){
if (destination.formula != "")
{cout << "uh-oh, " << destination.formula << " is being overwritten" << endl;};
destination.formula = x.formula;
destination.a = x.a;

}


Share this post


Link to post
Share on other sites
ps error with the copier function is this, which i've never gotten before using it in this code, it has been reading things in just fine before i ever tried to pass a class as an object:

error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!