. M file import C ++ header file error,. m Import

Source: Internet
Author: User

. M file import C ++ header file error,. m Import

I have dug a lot of pitfalls in my work over the past few days and encountered various strange mistakes. Now let's make a summary.

Create a new project, and then create the HelloCPP. h, HelloCPP. cpp file. The content of HelloCPP. h is as follows:

#ifndef __CPPWrong__HelloCPP__#define __CPPWrong__HelloCPP__//#include <stdio.h>namespace hello{    };#endif /* defined(__CPPWrong__HelloCPP__) 

Is an empty namespace.


Then Import HelloCPP. h In ViewController. m, as shown below:

# Import "ViewController. h "// import the C ++ header file # import" HelloCPP. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} -(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

Run, and an error is reported. The prompt is as follows:


The imported C ++ header file cannot recognize its namespace.


Solution:

Generally, in the project, if the C ++ code running exception is encountered in the OC, it is because the C ++ header file is referenced by an OC. m file. To achieve mixed compilation of OC and C ++, you mustModify the suffix of the referenced. m file to. mm..




An error occurred while importing the C ++ header file.

Delete this sentence and rewrite it. Note that the input method is English. I don't know if it doesn't work.

Why does the header file not be found when the c and H files are imported by VC?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.