简单的问题,这是有效的C++:
class Foo
{
void Foo::doSomething();
};
Run Code Online (Sandbox Code Playgroud)
这个问题的观点:是重复使用的类名和双冒号的方法名前有效的内部类的声明?
我在编译使用g ++ 4.2.3执行此操作的代码时遇到问题.在挖掘和更改代码之前,我很想看到对这里描述语法的内容的引用.或者降级编译器; 这确实是用g ++ 3.3.6构建的.
我得到的错误是(大致):
Foo.h:3: error: extra qualification ‘Foo::’ on member ‘doSomething’
Run Code Online (Sandbox Code Playgroud)
我做了谷歌,但无法想出一些东西.我没有标准,即使我这样做也可能需要一段时间才能找到任何权威的东西.我不是C++语言律师.
我试图更多地了解Objective-c,目前我被卡住了.我有4个错误,都是一样的."隐含的功能声明",我用Google搜索,但我找不到解决方案.
RadioStation .h
#import <Cocoa/Cocoa.h>
@interface RadioStation : NSObject {
NSString* name;
double frequency;
char band;
}
+(double)minAMFrequency;
+(double)maxAMFrequency;
+(double)minFMFrequency;
+(double)maxFMFrequency;
-(id)initWithName:(NSString*)newName atFrequency:(double)newFrequency withBand:(char)newBand;
-(NSString*)name;
-(double)frequency;
-(char)band;
-(void)setName:(NSString*)newName;
-(void)setFrequency:(double)newFrequency;
-(void)setBand:(char)newBand;
@end
Run Code Online (Sandbox Code Playgroud)
RadioStation .m
#import "RadioStation.h"
@implementation RadioStation
+(double)minAMFrequency{
return 520.0;
};
+(double)maxAMFrequency{
return 1610.0;
};
+(double)minFMFrequency{
return 88.3;
};
+(double)maxFMFrequency{
return 107.9;
};
-(id)initWithName:(NSString*)newName atFrequency:(double)newFrequency withBand:(char)newBand{
self = [super init];
if(self != nil){
name = [newName retain];
band = newBand;
if (band == 'F') {
if (newFrequency > maxFMFrequency()) { …Run Code Online (Sandbox Code Playgroud) 有人能告诉我结构声明的这两个版本之间的区别吗?
struct S
{
uint8_t a;
};
Run Code Online (Sandbox Code Playgroud)
和
const struct S
{
uint8_t a;
}
Run Code Online (Sandbox Code Playgroud)
其次是:
void main(void)
{
struct S s = {1};
s.a++;
}
Run Code Online (Sandbox Code Playgroud)
提示,我已经在 Visual Studio C++ 2010 Express 中尝试了 S 的两个版本,所以我知道两者都编译出错。
“const struct”什么都不做?"const struct S s = {1};" 当然可以,但这不是目前的问题。
问候丰富
/********************************************/
Run Code Online (Sandbox Code Playgroud)
我刚刚弄清楚了什么
const struct <typename> <{type}> <variable instances a, b, .., z>;
Run Code Online (Sandbox Code Playgroud)
是在做:
当 const 出现在“struct”之前时,所有变量实例都是 const,就好像它们被定义为:
const struct <typename> a, b, z;
Run Code Online (Sandbox Code Playgroud)
所以它确实做了一些事情,但当没有与结构声明一致的实例定义时就不会。
富有的
请考虑以下代码:
struct Foo
{
};
struct Bar
{
explicit Bar(const Foo&)
{
}
};
int main()
{
Foo foo;
Bar bar(foo); // Okay.
Bar(foo); // Will not compile.
(Bar(foo)); // Okay. Unnamed temporary requires parenthesis.
}
Run Code Online (Sandbox Code Playgroud)
为什么需要临时版本的括号?他们解决了什么含糊之处?
我的预感是:我认为编译器看作Bar(foo)是一个函数的声明,但我不确定为什么会出现这种情况,因为foo(实例)不是一个类型.因此,括号强制将上述内容视为表达,而不是前瞻性声明.
在阅读此文章中,我碰到的函数指针的以下声明.我没有使用过这样的声明,但我解释它的方式是:当取消引用时,functionFactory的返回值是一个接受2个int的函数并返回一个int.
int (*functionFactory(int n))(int, int) {
printf("Got parameter %d", n);
int (*functionPtr)(int,int) = &addInt;
return functionPtr;
}
Run Code Online (Sandbox Code Playgroud)
我很想知道这样的声明是针对这种情况还是有一种我错过的通用方法.
我的意思是我们通常会看到类似的声明
<returnType> funcName(listOfArgs){}
Run Code Online (Sandbox Code Playgroud)
这个出现在联盟之外.请有人详细说明.
关于C编程的快速问题.我没有参加过课程,但是正在网上阅读指针和使用的各种符号.以下行是否会产生一个包含10个整数指针的数组,或者指向10个整数数组的指针?
int *x[10];
Run Code Online (Sandbox Code Playgroud)
以下结果也会产生一个函数,它接受一个double作为输入并返回一个指向字符的指针?
char (*f) (double a);
Run Code Online (Sandbox Code Playgroud)
提前致谢!
编辑:错误地输入第一行代码.
以下代码将根据 cppquiz.org 进行编译并具有确定性(问题 #30)
#include <iostream>
struct X {
X() { std::cout << "X"; }
};
int main() { X x(); }
Run Code Online (Sandbox Code Playgroud)
程序的输出什么都不是,因为
X x();
Run Code Online (Sandbox Code Playgroud)
是一个函数声明。
但是我仍然想知道为什么这个会编译,尽管这个声明从未在任何地方定义过?
以下函数定义/声明的含义如下:
maxCollatz :: (Integer, Integer)
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为我不确定参数是什么,因此产生了什么.因为通常->在函数定义中有.E. g.Int -> Int.
PS再次抱歉这类问题.
当宣布在C++对象-
有什么区别
MyClass myObj (a,b,c);
Run Code Online (Sandbox Code Playgroud)
(我理解这是调用带有三个参数的构造函数)
与
MyClass myObbj{a,b,c};
Run Code Online (Sandbox Code Playgroud)
不确定这里的花括号是什么意思?
作为参考,我使用以下代码
// Inertial Navigation EKF
NavEKF EKF{&ahrs, barometer, sonar};
AP_AHRS_NavEKF ahrs{ins, barometer, gps, sonar, EKF};
Run Code Online (Sandbox Code Playgroud)
1.在NavEKF EKF中是否使用大括号{&ahrs,barometer,sonar}; c ++标准的一部分.gcc 4.6.1抱怨 - 函数定义不声明参数.
2.给定AP_AHRS_NavEKF ahrs;
AP_Baro晴雨表;
RangeFinder声纳;
2A.为什么编译器会抱怨这个
NavEKF EKF(&ahrs,晴雨表,声纳);
但允许这个
NavEKF EKF(AP_AHRS_NavEKF&ahrs,AP_Baro晴雨表,RangeFinder声纳);
6.3版本接受以下内容作为有效c代码gcc:
char white[] = { 'a', 'b', 'c' };
char blue[] = "abc";
char *red = "abc";
Run Code Online (Sandbox Code Playgroud)
但是以下失败:
char *green = { 'a', 'b', 'c' }; // gcc error
Run Code Online (Sandbox Code Playgroud)
我确信这是一个非常合理的理由,但我想知道它是什么.这个问题是由具有初始化字节数组(所以当案件的动机unsigned char,而不是char),这是非常诱人的喜欢写东西{ '\x43', '\xde', '\xa0' },而不是"\x43\xde\xa0",并且只要你忘了写my_array[],而不是*my_array,你被编译器捕获.
declaration ×10
c ×4
c++ ×4
function ×4
definition ×2
syntax ×2
c++11 ×1
classname ×1
constants ×1
haskell ×1
objective-c ×1
pointers ×1
string ×1
struct ×1