English 中文(简体)
C++ 使用头盔和杂质档案的班级
原标题:C++ Class using header and implemenation files
  • 时间:2010-01-20 19:56:13
  •  标签:
  • c++

一. 简单C++ 实践的“世界之声”方案;不幸的是,在汇编后,我发现了一些错误:

预计......

错误:Hello World (std:string, :string:string)与HelloWorld的类别不符。

下面是我的法典,谁能帮助我了解我失踪/忽视的是什么? 感谢。

<>Header:

  1 #ifndef HELLOWORLD_H_ 
  2 #define HELLOWORLD_H_
  3 #include <string>
  4 
  5 class HelloWorld
  6 {
  7     public:
  8         HelloWorld();
  9         HelloWorld(string fName, string lName);
 10         ~HelloWorld();
 11 };
 12 
 13 #endif

<>执行>:

  1 #include <iostream>
  2 #include <string>
  3 #include "HelloWorld.h"
  4 
  5 using namespace std;
  6 
  7 HelloWorld::HelloWorld()
  8 {
  9     cout << "Hello, anonymous!";
 10 }
 11 
 12 HelloWorld::HelloWorld(string fName, string lName)
 13 {
 14     cout << "Hello, " << fName <<     << lName << endl;
 15 }
 16 
 17 HelloWorld::~HelloWorld()
 18 {
 19     cout << "Goodbye..." << endl;
 20 }
最佳回答

页: 1 因为这些定义是在固定名称空间内确定的。

HelloWorld(std::string fName, std::string lName);

由于你专门进口这一名称。 然而,解决办法不是在你的主人档案中进口这一名称空间(通常在C++中说是坏话)。

问题回答

如果该守则与你对该问题的描述完全一样,造成这一错误的最可能原因是,在标题中,汇编者没有确定“<<<>>>指示/编码”的含义,因为它不是全球名称空间的象征。 完全有资格:

class HelloWorld
{
//...
   HelloWorld( std::string fName, std::string lName );
};




相关问题
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?

热门标签