missing type specifier - int assumed

Mar 12, 2013 at 9:27pm
So, I got 2 different .cpp file(human.cpp and pet.cpp) (I can't create header file for class definition)

Human object has pet as its private instance.

In the pet class, I define this struct:

struct toy
{
int countToy;
string toyName;
}

and pet object has vector of toy as its private instance. So far, it works just fine. However, in the a function in human class that pass toy object? how can I possibly do this? should I define the struct toy in human class? thx
Mar 12, 2013 at 10:36pm
> I can't create header file for class definition
¿why not?

> In the pet class, I define this struct:
¿do you mean as an `inner class'?

> in the a function in human class that pass toy object?
¿what?
Mar 12, 2013 at 10:39pm
My be I misunderstand you. Is this ok:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Pet
{
public:
    struct Toy
    {
        int countToy;
        string toyName;
    }

private:
    std::vector<Toy> _toys;
}

class Human
{
private:
    Pet _p;

public:
    void f(Pet::Toy aToy);

};
Mar 13, 2013 at 1:34am
yeah that's what I write. However, I separate pet class and human class into 2 different .cpp file. what should I put in the #include in the human class? because I don't have any pet.h class. thank you
Mar 13, 2013 at 9:22am
In C/C++ there's syntactically no need for special specification/implementation files like in modern high-level languages. But usually specifications like those above will be put in header files one file for each class. By convention the files prefixes are named by the classes name. On top of "Human.h" you will include "Pet.h". Your example will only need an implementation file "Human.cpp" to define implementation of f().
Topic archived. No new replies allowed.