English 中文(简体)
无效使用未定义的碎片
原标题:Invalid use of undefined type struct PelephonePH
  • 时间:2011-06-03 12:07:23
  •  标签:
  • c++

i have received in .cpp errors of invalid use of undefined struct PelephonePN, CellcomPN and so on and also error in .h errors of forward declaration of PelephonePN,...

#ifndef PHONE_H_INCLUDED
#define PHONE_H_INCLUDED
#include <iostream>
#include <ctime>
#include <string>
#include "phone.h"

using namespace std;

class PhoneNumber;
class PelephonePN;
class CellcomPN;
class OrangePN;
class HotPN;
class BezeqPN;

class PhoneManager
{
private:
    PelephonePN* mpPelephone;
    CellcomPN* mpCellcom;
    OrangePN* mpOrange;
    HotPN* mpHot;
    BezeqPN* mpBezeq;
public:
    PhoneManager();
    ~PhoneManager();
    void split_check_data(string str);
};

#endif

and .cpp

#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include "phone_manager.h"
#include "phone.h"


using namespace std;

PhoneManager::PhoneManager()
{
    srand(time(0));
    mpPelephone = new PelephonePN();
    mpCellcom = new CellcomPN();
    mpOrange = new OrangePN();
    mpHot = new HotPN();
    mpBezeq = new BezeqPN();
    mpPelephone->add(mpCellcom);
    mpPelephone->add(mpOrange);
    mpPelephone->add(mpHot);
    mpPelephone->add(mpBezeq);
    mpBezeq->setNext(mpPelephone);
}
问题回答

To instantiate an object, forward declaration is just insufficient. Include the corresponding headers in the source file. In the body of the constructor, you are instantiating mpPelephone, ..... So, make sure that corresponding class headers can be seen in the translation unit.

。 页: 1 标有<条码>的负责人及其联系人。

forward-declare> 标题中,如果你只是把标题或参考资料作为参照点或参考点使用,则标题中的“,但你开始<>使用<>>。 在执行过程中,你需要向汇编者提供finition

You can t use a forward declaration of a class to access its members (which includes the constructor, default or otherwise) or its size and without those two things, you can t instantiate an instance of that class.

You require its FULL implementation to do that, so in your .cpp file you need to include the header with the whole class PelephonePN {/* class body */}; section.

在第一份档案中,有线索:

#ifndef PHONE_H_INCLUDED
#define PHONE_H_INCLUDED

我在电话中听说有同样的线,请查......

Are your PelephonePN and co. in a particular namespace? If so, predeclarations must all be in the same namespace. Since you added a using namespace std (sigh), my guess is that phone.h is defining your classes inside the namespace std (I hope it doesn t, but that s another thing). If so, your predeclarations must be: namespace std { class PelephonePN; }

Btw,什么是个耳? O.O.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签