Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284667
  • 博文数量: 82
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 874
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-21 09:58
个人简介

traveling in cumputer science!!

文章分类

全部博文(82)

文章存档

2016年(13)

2015年(69)

我的朋友

分类: C/C++

2015-04-06 23:27:00

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

点击(此处)折叠或打开

  1. /***************************
  2.  *filename:hello.cc

  3.  *filedescription:test

  4.  *writer:warrior

  5.  *date:2015/4/5

  6.  *mail:675979646@qq.com
  7.  **************************/

  8. //include
  9. #include "hello.h"


  10. using namespace std;
  11. //define


  12. //variable

  13. //class


  14. //function

  15. /*********************
  16.  *function name:void hello()

  17.  *function discription:

  18.  *parameter:
  19.     input: NULL
  20.     output: NULL
  21.  ********************/
  22. void Printer::Hello()
  23. {
  24.     char name[10];
  25.     cout<<"Please input your name :"<<endl;
  26.     cin>>name;
  27.     cout<<"Hello C++!"<<endl;
  28.     cout<<"I am "<<name<<" ."<<endl;
  29. };

hello.h

点击(此处)折叠或打开

  1. #ifndef _HELLO_H_
  2. #define _HELLO_H_
  3. //include
  4. #include <iostream>
  5. #include <sstream>

  6. class Printer
  7. {
  8.     private:
  9.         int Serial_Number;
  10.     public:
  11.         void Hello();
  12. };
  13. #endif

main.cc

点击(此处)折叠或打开

  1. /***************************
  2.  *filename:main.cc

  3.  *filedescription:test

  4.  *writer:warrior

  5.  *date:2015/4/5

  6.  *mail:675979646@qq.com
  7.  **************************/
  8. //include
  9. #include "main.h"

  10. using namespace std;
  11. //define


  12. //variable


  13. //function

  14. /*********************
  15.  *function name:int main()

  16.  *function discription:the main function

  17.  *parameter:
  18.     input: NULL
  19.     output: NULL
  20.  ********************/
  21. int main()
  22. {
  23.     Printer My_Printer;
  24.     My_Printer.Hello();
  25.     return 0;
  26. }

main.h

点击(此处)折叠或打开

  1. #ifndef _MAIN_H_
  2. #define _MAIN_H_

  3. #include <stdio.h>
  4. #include "hello.h"
  5. #endif

makefile

点击(此处)折叠或打开

  1. #makefile demo V1.0
  2. #author: warrior
  3. #mail:675979646@qq.com
  4. #date:2015/4/5

  5. CXX := g++
  6. CFLAGS := -c -g -W -Wall
  7. DIR := ./

  8. SOURCES := $(shell ls *.cc)
  9. OBJS := $(patsubst %.cc,%.o,$(SOURCES))
  10. TARGET := target


  11. ${TARGET} : ${OBJS}
  12.     ${CXX} -o $@ $^

  13. %.o : %.cc
  14.     $(CXX) ${CFLAGS} -o $@ $<




  15. .PHONY : clean
  16. clean :
  17.     -rm -f *.o target



阅读(2840) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~