0
我有一個頭文件:啊'MYV' 沒有指定類型
#include <iostream>
class A
{
int m_a;
public:
A(int a);
};
和源文件a.cpp
#include "a.h"
#include <vector>
#include <string>
using namespace std;
vector<string>myV;
myV.push_back("a");
A::A(int a)
{
m_a = a;
}
我在編譯上述程序CentOs-7.2使用:g ++ a.cpp
編譯上述程序米我得到這個錯誤:
a.cpp:8:1: error: ‘myV’ does not name a type
myV.push_back("a");
任何人都可以幫助我在這個錯誤?
你不能任何功能之外運行的代碼,所以編譯器是治療'myV'作爲一個類型,而解析。 – whoan
你可以_declare_在函數之外的東西,但是你不能調用它們的函數(即你的'myV'聲明沒問題,但是'push_back'不是) – Tas