首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个程序不能在VC++2008Express中编译?

为什么这个程序不能在VC++2008Express中编译?
EN

Stack Overflow用户
提问于 2011-10-25 00:14:41
回答 1查看 3K关注 0票数 0

此程序在TC++ 3.0上编译和运行。

为什么这个程序不能在VC++2008Express中编译?

代码语言:javascript
复制
#include <iostream>

using namespace std;

class MyClass
{
private:
    class MyNestedClass
    {
    private:
        int myInteger;

    public:
        MyNestedClass(int a)
        {
            myInteger = a;
        }
        void Show()
        {
            cout<<myInteger;
        }
    };
};

int main()
{
    MyClass::MyNestedClass myNestedClassObject(100);

    myNestedClassObject.Show();
}

将显示以下消息:

代码语言:javascript
复制
1>------ Rebuild All started: Project: Test, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'Test', configuration 'Debug|Win32'
1>Compiling...
1>Static_Data_Member.c
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(39) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(39) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(41) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(42) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(43) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(44) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(45) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(46) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(47) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(48) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(49) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(49) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(49) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(49) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(50) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(50) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(50) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(50) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(51) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(52) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(53) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(54) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(55) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(56) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdio(56) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(21) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : error C2143: syntax error : missing '{' before ':'
1>c:\program files\microsoft visual studio 9.0\vc\include\cstdlib(23) : fatal error C1003: error count exceeds 100; stopping compilation
1>Build log was saved at "file://h:\Test\Debug\BuildLog.htm"
1>Test - 102 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-25 00:16:22

这是一个C++程序,但是您已经为源文件提供了一个.c扩展名。

默认情况下,Visual C++编译器将.c文件编译为C。使用.cpp扩展或使用/TP标志编译时,将源代码编译为C++。

但是,即使您将源代码编译为C++,程序仍然是无效的。MyNestedClassMyClass的私有成员类型,因此您不能在main()中构造它的实例。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7878620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档