Ultra-basic C++ question

J

James

I have a class called Manager, which I want to instantiate in my driver
class. It is in a file called Manager.cpp. Manager has no constructors set
up.

I also have a driver class and I want to create a Manager object called
manager in my main function of the driver class.

I used the code:

Manager manager;


However i get errors such as "Manager: undeclared identifier" and "syntax
error : missing ';' before indentifier 'manager'" when I try to compile.

What am I doing wrong?
 
M

mlimber

James said:
I have a class called Manager, which I want to instantiate in my driver
class. It is in a file called Manager.cpp. Manager has no constructors set
up.

I also have a driver class and I want to create a Manager object called
manager in my main function of the driver class.

I used the code:

Manager manager;


However i get errors such as "Manager: undeclared identifier" and "syntax
error : missing ';' before indentifier 'manager'" when I try to compile.

What am I doing wrong?

You need to put the class declaration in a header file (perhaps,
Manager.hpp) and then include it in other .cpp or .hpp files that need
it. For instance:

// File: Manager.hpp
class Manager
{
public:
void DoSomething();
// other functions and data members
};


// File: Manager.cpp
#include "Manager.hpp"

void Manager::DoSomething()
{
// ...
}


// File: Main.cpp
#include "Manager.hpp"

int main()
{
Manager manager;
manager.DoSomething();
// ...
return 0;
}

You could also define the functions of Manager in the header if they're
small. It might slow down compilation, however, if Manager.hpp is large
gets included many times throughout the project.

Cheers! --M
 
D

Dan Cernat

James said:
I have a class called Manager, which I want to instantiate in my driver
class. It is in a file called Manager.cpp. Manager has no constructors set
up.

I also have a driver class and I want to create a Manager object called
manager in my main function of the driver class.

I used the code:

Manager manager;


However i get errors such as "Manager: undeclared identifier" and "syntax
error : missing ';' before indentifier 'manager'" when I try to compile.

What am I doing wrong?

in driver.h

#include "Manager.h"

or show us your code

/dan
 
V

Victor Bazarov

James said:
I have a class called Manager, which I want to instantiate in my driver
class. It is in a file called Manager.cpp. Manager has no constructors set
up.

I also have a driver class and I want to create a Manager object called
manager in my main function of the driver class.

I used the code:

Manager manager;


However i get errors such as "Manager: undeclared identifier" and "syntax
error : missing ';' before indentifier 'manager'" when I try to compile.

What am I doing wrong?

The file with the driver code has to somehow have the definition of the
'Manager' class available to it. The usual approach is to put the class
definition in a header file, like so

// this is 'Manager.h' file:
#ifndef MANAGER_H_INCLUDED // those are called 'double inclusion
#define MANAGER_H_INCLUDED // guards', read about them elsewhere

class Manager {
...
};

#endif
// end of 'Manager.h' file

then include that header in *both* the 'Manager.cpp' and the file where
the driver code is:

#include "Manager.h"
...

V
 
D

Default User

James said:
I have a class called Manager, which I want to instantiate in my
driver class. It is in a file called Manager.cpp. Manager has no
constructors set up.

I also have a driver class and I want to create a Manager object
called manager in my main function of the driver class.

I used the code:

Manager manager;


However i get errors such as "Manager: undeclared identifier" and
"syntax error : missing ';' before indentifier 'manager'" when I try
to compile.

What am I doing wrong?

You failed to present a complete, minimal program that produces the
problem. How can we comment on code you don't show us? Don't describe
your code, paste it in directly.



Brian
 
J

James

Default User said:
You failed to present a complete, minimal program that produces the
problem. How can we comment on code you don't show us? Don't describe
your code, paste it in directly.

The description I gave appears to have been enough, because it's been
answered in all three responses (except yours).

Thanks all.
 
D

Default User

James said:
The description I gave appears to have been enough, because it's been
answered in all three responses (except yours).

Thanks all.

Demonstrating merely that the people here are clever enough to deduce
what your problem was, not anything you did (copping an attitude
doesn't count).

Please the FAQ about how to post questions properly.


Brian
 
J

James

Default User said:
Demonstrating merely that the people here are clever enough to deduce
what your problem was, not anything you did (copping an attitude
doesn't count).

It didn't require anything "clever" to work out what I was asking.
Please the FAQ about how to post questions properly.

No, sorry don't have the time or need to.
 
P

Puppet_Sock

James said:
No, sorry don't have the time or need to.

Sigh. James, you just put the kiss-o-death on your posting
here. If you *won't* read the FAQ, why should anybody help
you? You should now change your screen name so others won't
know it's this person who couldn't bother with the FAQ.
Socks
 
J

James

Puppet_Sock said:
Sigh. James, you just put the kiss-o-death on your posting
here. If you *won't* read the FAQ, why should anybody help
you? You should now change your screen name so others won't
know it's this person who couldn't bother with the FAQ.

Sigh. My handle is totally made-up and I change it every couple of days
anyway. I have no history or reputation to protect so a change of name means
nothing to me.

BTW Why is it these kind of newsgroups are full of self-important control
freaks? I appreciate the help that people give me, and the majority are
helpful and friendly, but some people *really* need to get a life.
 
P

Puppet_Sock

James wrote:
[snip]
BTW Why is it these kind of newsgroups are full of self-important control
freaks?

I don't know. Why *do* you infest newsgroups?
I appreciate the help that people give me, and the majority are
helpful and friendly, but some people *really* need to get a life.

No. You don't appreciate the help people give you, else you'd
read the FAQ.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top