When I test to code in CPP, I meet a problem. And It's error:aggregate ‘Printer My_Printer’ has incomplete type and cannot be defined.
After my debug I realized that there is an error in my statement in class. I statement my class in hello.cc file is fault, And when I move the statement into hello.h file the error is disappear.
hello.cc
hello.h
main.cc
main.h
makefile
阅读(49) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
After my debug I realized that there is an error in my statement in class. I statement my class in hello.cc file is fault, And when I move the statement into hello.h file the error is disappear.
hello.cc
点击(此处)折叠或打开
- /***************************
- *filename:hello.cc
-
- *filedescription:test
-
- *writer:warrior
-
- *date:2015/4/5
-
- *mail:675979646@qq.com
- **************************/
-
- //include
- #include "hello.h"
-
-
- using namespace std;
- //define
-
-
- //variable
-
- //class
-
-
- //function
-
- /*********************
- *function name:void hello()
-
- *function discription:
-
- *parameter:
- input: NULL
- output: NULL
- ********************/
- void Printer::Hello()
- {
- char name[10];
- cout<<"Please input your name :"<<endl;
- cin>>name;
- cout<<"Hello C++!"<<endl;
- cout<<"I am "<<name<<" ."<<endl;
- };
hello.h
点击(此处)折叠或打开
- #ifndef _HELLO_H_
- #define _HELLO_H_
- //include
- #include <iostream>
- #include <sstream>
-
- class Printer
- {
- private:
- int Serial_Number;
- public:
- void Hello();
- };
- #endif
main.cc
点击(此处)折叠或打开
- /***************************
- *filename:main.cc
-
- *filedescription:test
-
- *writer:warrior
-
- *date:2015/4/5
-
- *mail:675979646@qq.com
- **************************/
- //include
- #include "main.h"
-
- using namespace std;
- //define
-
-
- //variable
-
-
- //function
-
- /*********************
- *function name:int main()
-
- *function discription:the main function
-
- *parameter:
- input: NULL
- output: NULL
- ********************/
- int main()
- {
- Printer My_Printer;
- My_Printer.Hello();
- return 0;
- }
main.h
点击(此处)折叠或打开
- #ifndef _MAIN_H_
- #define _MAIN_H_
-
- #include <stdio.h>
- #include "hello.h"
- #endif
makefile
点击(此处)折叠或打开
- #makefile demo V1.0
- #author: warrior
- #mail:675979646@qq.com
- #date:2015/4/5
-
- CXX := g++
- CFLAGS := -c -g -W -Wall
- DIR := ./
-
- SOURCES := $(shell ls *.cc)
- OBJS := $(patsubst %.cc,%.o,$(SOURCES))
- TARGET := target
-
-
- ${TARGET} : ${OBJS}
- ${CXX} -o $@ $^
-
- %.o : %.cc
- $(CXX) ${CFLAGS} -o $@ $<
-
-
-
-
- .PHONY : clean
- clean :
- -rm -f *.o target
相关热门文章
给主人留下些什么吧!~~
评论热议