• Advertisement
Sign in to follow this  

C++ definition error

This topic is 3573 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, I have three files, common.h, container.h and container.cpp. Common.h defines a structure called Info, which hold a pointer to the class Container. Container.h defines a class called Container, which hold an Info object. Container.cpp fills the Info object, by passing 'this' to fill the pointer in Info to it-self. The (parent) container class has a vector of (sub) container classes, in these sub container classes the Info object should have a pointer to the parent container. Thats why I fill the Info object with 'this' from within the parent. The error I get, is that the functions in Info are not defined.
// common.h

#ifndef COMMON_H
#define COMMON_H

#include <string>

class Container;

struct Info
    int id;
    std::string name;
    Container *parent;

    Info() : id(-1), parent(NULL) {}
    Info(int id, Container *parent) : id(id), parent(parent) {}
    Info(int id, std::string name, Container *parent) : id(id), name(name), parent(parent) {}

#endif // COMMON_H
// container.h


#include <vector>

#include "gui/common.h"

class Container
    void add(Container &iitem); // add container

    Info info;

    std::vector<Container *> containers;

#endif // CONTAINER_H
// container.cpp

#include "gui/container.h"

void Container::add(Container &iitem)
    Container *item = new Container;
    *item = iitem;

    item->info((int) layers.size(), this);
Errors I get with the MingW compiler:
E:\C\GUI\gui\container.cpp: In member function `void Container::add(Container&)':
E:\C\GUI\gui\container.cpp:92: error: no match for call to `(Info) (int, Container* const)'
What could be possibly wrong? I'm out of idea's =/ Thanks, Decrius

Share this post

Link to post
Share on other sites
the compiler is right about the line number and error.

You try to access a constructor but at this time the object already exists
so you can´t call it:
item->info((int) layers.size(), this);

Something like that may work:
(If everything is correct a temporary Info object is created and you assign
the Info object from the class the values of the temp-Object)

item->info = Info((int) layers.size(), this);

Share this post

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

  • Advertisement